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

Large performance regression in Swing text layout.

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • Resolved In Build:
      b36

      Description

      This bug was reported on Swing alias by Alan Snyder <javalists@cbfiddle.com>

      The performance downgrade is rather big > 20x.

      Test to benchmark the layout:
      ===================================

      import javax.swing.JTextPane;
      import javax.swing.text.BadLocationException;
      import javax.swing.text.DefaultStyledDocument;
      import javax.swing.text.Element;
      import javax.swing.text.SimpleAttributeSet;
      import javax.swing.text.View;

      public class Test {
       public static void main(String[] args) {
        boolean isRepeat = args.length > 0 && args[0].equals("repeat");
        new Test(isRepeat ? 1000 : 1);
       }

       public Test(int count) {
        TestRunner r = new TestRunner();
        for (int i = 0; i < 100; i++) {
         r.runTest();
        }
        for (int counter = 0; counter < count; counter++) {
         long ts1 = System.currentTimeMillis();
         for (int i = 0; i < 2000; i++) {
          r.runTest();
         }

         long ts2 = System.currentTimeMillis();
         System.err.println("Test: " + (ts2 - ts1) + " milliseconds");
        }
       }

       class TestRunner {
        View view;
        int counter;
        float width;
        float height;

        TestRunner() {
         try {
          DefaultStyledDocument doc = new DefaultStyledDocument();
          String text = createText();
          doc.insertString(0, text, new SimpleAttributeSet());
          Element p = doc.getParagraphElement(0);
          JTextPane pane = new JTextPane(doc);
          view = pane.getUI().getRootView(pane);
         } catch (BadLocationException ex) {
          throw new UnsupportedOperationException(ex);
         }
        }

        void runTest() {
         counter++;
         if (counter % 2 == 0) {
          width = 600;
          height = 600;
         } else {
          width = 800;
          height = 400;
         }
         view.setSize(width, height);
        }

        String createText() {
         String s = "Inserts some content into the document. Inserting content causes a write lock to be held while the actual changes are taking place, followed by notification to the observers on the thread that grabbed the write lock. ";
         return s + s + s + s + s + "\n";
        }
       }
      }




        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                prr Philip Race
                Reporter:
                ssadetsky Semyon Sadetsky
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: