Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8202131

LineBreakMeasurer is 10 times slower in JDK10 than in JDK8

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • CPU:
      x86_64
    • OS:
      windows_10

      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


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                prr Philip Race
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: