JDK-8202131 : LineBreakMeasurer is 10 times slower in JDK10 than in JDK8
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 9,10,11
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2018-04-20
  • Updated: 2025-08-08
  • Resolved: 2025-08-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
The linebreaker.nextLayout() method is 10 times slower since the first JDK9 update.
I need it to draw multiline text in a canvas or to evaluate the height of a multi-line text in a grid cell.
I did a very simple test case which reproduce it always. The  "textLayout.draw(g, 0, y);" is not necessary to reproduce the problem.

REGRESSION : Last worked in version 8u172

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the following program with JDK8 and JDK 10

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It takes 1341ms with JDK8
ACTUAL -
It takes 15731ms with JDK10
It takes more than 15s too with the JDK11-ea+10 too.

---------- BEGIN SOURCE ----------
package Tests;



import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextLayout;
import java.text.AttributedString;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {

  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    long lTime = System.currentTimeMillis();
    int y = 0;
    for (int i = 0 ; i < 10000; i++) {
      y = drawParagraph(g2d, "adfasdfaf", 20, y);
    }
    System.out.println(System.currentTimeMillis() - lTime + " Milli-seconds");
  }

  int drawParagraph(Graphics2D g, String paragraph, float width, int yPosition) {
    LineBreakMeasurer linebreaker = new LineBreakMeasurer(new AttributedString(paragraph)
        .getIterator(), g.getFontRenderContext());

    int y = yPosition;
    while (linebreaker.getPosition() < paragraph.length()) {
      TextLayout textLayout = linebreaker.nextLayout(width);
      // Unecessary part of the test
      y += textLayout.getAscent();
      textLayout.draw(g, 0, y);
      y += textLayout.getDescent() + textLayout.getLeading();
    }
    return y;
  }

  public static void main(String[] args) {

    JFrame frame = new JFrame("Basic Shapes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Main());
    frame.setSize(350, 250);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Great, thanks for checking!
08-08-2025

Tested on Windows - times are approximate 8u: 1500ms 11: 20000ms 12: 20000ms 13: 500ms 17: 500ms 21: 500ms 24 : 500ms So JDK 13 fixed it and that's what has the fix for https://bugs.openjdk.org/browse/JDK-8220231
08-08-2025

Perhaps this is the one 8220231: Cache HarfBuzz face object for same font's text layout calls ?
07-08-2025

I think there was a specific fix .. I'll try to hunt it down so we can close as a dup. I like proper closure in these cases.
06-08-2025

[~prr] This one is probably OK to close, IMO. LineBreakMeasurer performance seems to be quite good these days (Java 24), relative to Java 8. What do you think?
06-08-2025

This should be largely mitigated already if not entirely. Deferring further investigation of any other improvements.
06-05-2019

See also http://mail.openjdk.java.net/pipermail/2d-dev/2018-September/009453.html
08-09-2018

This is somehow related to harfbuzz. With JDK9 if I specify -Dsun.font.layoutengine=icu then the performance returns to JDK 8 levels.
25-04-2018

Reported with JDK 10.0.1, the linebreaker.nextLayout() method is 10 times slower then JDK 8 update (8u171) Verfied this foe the affected version and could confirm the results. Results: ========= 8u172: 1983 Milli-seconds 9: 24553 Milli-seconds 9.0.4: 28380 Milli-seconds 10: 25720 Milli-seconds 10.0.1: 24024 Milli-seconds 11 ea b09: 23788 Milli-seconds This is a performance regression in JDK 9 and above when compared to JDK 8 update. To verify, run the attached test case with respective JDK version.
23-04-2018