JDK-8222915 : getBounds() method of TextLayout is very slow with HarfBuzz font engine (Windows)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 9,11.0.3-oracle,13
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-04-23
  • Updated: 2019-07-12
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
tbdUnresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Window 10, Java 10 and onwards

A DESCRIPTION OF THE PROBLEM :
Performance degredation of getBounds() method of java.awt.font.TextLayout
We are observing performance degradation by many fold when using HarfBuz as a font engine when data is large.
In our specific use case we are using poi library that using making use of TextLayout to get the width of every column. We are wiriting 20000 rows to spreadsheet :
With ICU as font engine : 2.3 to 3 seconnds
With HarfBuzz as font engine : 50 to 80 seconnds

REGRESSION : Last worked in version 8u212

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
call getBounds() method of TextLayout for large data set i.e. for large number of TextLayouts.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Total time consumed in java 8 and java 10 & above should be nearly same.
Expected Time consumed arround 1.5 seconds
ACTUAL -
Total time consumed in java 10  & above is much much high than  time consumed in java 8.
Actual Time consumed more than 40 seconds

---------- BEGIN SOURCE ----------
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.text.AttributedString;

public class TextlayoutPerf {

    private static final FontRenderContext fontRenderContext = new FontRenderContext(null, true, true);

    public static void main(String[] args){

        long start = System.currentTimeMillis();
        String text = "test test test stet test test test test test";
        //Equivalent to 20000 rows and 2 column
        for (int j = 0; j < 3 ; j++) {
            for (int i = 0; i < 20000; i++) {
                getCellWidth(15, 0, 25, new AttributedString(text));
            }
        }

        System.out.print(System.currentTimeMillis() - start);

    }

    private static double getCellWidth(int defaultCharWidth, int colspan, double minWidth, AttributedString str) {
        TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
        final Rectangle2D bounds;
        long start1 = System.currentTimeMillis();
        bounds = layout.getBounds();

        // frameWidth accounts for leading spaces which is excluded from bounds.getWidth()
        final double frameWidth = bounds.getX() + bounds.getWidth();
        return frameWidth;
    }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
No workarround in java 10

FREQUENCY : always



Comments
On Ubuntu Linux I get 8u181: 10596ms jdk-10: 4254ms jdk-11: 4643ms jdk-12: 4773ms jdk-13 b18: 2103ms On Windows 7 I get 8u121: 21388ms jdk-10: 51372ms jdk-11: 50794ms jdk-12: 43992ms jdk-13 b18: 11076ms All are 64 bit VMs. Ignore the small differences and variation, and note that the Windows & Linux boxes are quite different in underlying performance What is interesting is that on Linux JDK-10 is faster, but slower on Windows - why ? But I do not see the 30X performance difference seen by the submitter. Also jdk13-b18 has improved the performance in all cases to better than JDK8u - at least for me.
26-04-2019

I see JDK 13 b17 was tested. b18 has a fix that may help here : https://bugs.openjdk.java.net/browse/JDK-8220231
25-04-2019

getBounds() method of TextLayout is very slow with HarfBuz font engine (Windows) As per description, getBounds() method of java.awt.font.TextLayout has performance degradation from JDK 9 and onward. Difference is observed when using HarfBuz as a font engine with large data. Checked this for reported versions and could confirm the results. Results: ======== 8: 14s 8u212: 14s 9: 45s 13 ea b17: 45s This is a performance regression in JDK 9 and onward. To verify, run the attached test case with respective JDK versions.
24-04-2019