-
Bug
-
Resolution: Unresolved
-
P3
-
9, 10, 11
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
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
- duplicates
-
JDK-8214573 Glyph layout performance degradation
-
- Closed
-