[OpenJDK 2D-Dev] Speed of drawPolyline on JDK11
Laurent Bourgès
bourges.laurent at gmail.com
Tue Oct 9 14:52:27 UTC 2018
Hi Peter,
I tried on my linux laptop (i7 + nvidia binary driver) and my results are
the same on OpenJDK 8 / 11:
*- Java: 1.8.0_181 25.181-b13oct. 09, 2018 4:29:31 PM polylinetest.Canvas
paintComponentINFOS: Paint Time: 0,078soct. 09, 2018 4:29:31 PM
polylinetest.Canvas paintComponentINFOS: Paint Time: 0,032s*
*- Java: 11 11+28oct. 09, 2018 4:33:17 PM polylinetest.Canvas
paintComponentINFO: Paint Time: 0,058soct. 09, 2018 4:33:17 PM
polylinetest.Canvas paintComponentINFO: Paint Time: 0,03s*
Maybe it is related to your hardware, as such graphics calls should be
handled direclty by the accelerated pipelines ... XRender on linux.
Here are netbeans hotspots:
Name Self Time Self Time (CPU) Total Time Total Time (CPU) Hits
sun.java2d.xr.XRRenderer$XRDrawHandler.drawLine (int, int, int, int) 599 ms
(8,9 %) 599 ms (39 %) 702 ms (0,8 %) 702 ms (1,3 %) 393
sun.java2d.xr.XRBackendNative.XRenderRectanglesNative[native] (int, byte,
short, short, short, short, int[], int) 327 ms (4,9 %) 327 ms (21,3 %) 327
ms (0,4 %) 327 ms (0,6 %) 21
sun.java2d.loops.ProcessPath.doProcessPath
(sun.java2d.loops.ProcessPath.ProcessHandler, java.awt.geom.Path2D.Float,
float, float) 109 ms (1,6 %) 109 ms (7,1 %) 836 ms (0,9 %) 836 ms (1,5 %) 21
sun.java2d.xr.XRDrawLine.rasterizeLine (sun.java2d.xr.GrowableRectArray,
int, int, int, int, int, int, int, int, boolean, boolean) 85,1 ms (1,3 %) 85,1
ms (5,5 %) 103 ms (0,1 %) 103 ms (0,2 %) 458
sun.awt.X11.XInputMethod.createXICNative[native] (long) 46,9 ms (0,7 %) 46,9
ms (3,1 %) 46,9 ms (0,1 %) 46,9 ms (0,1 %) 1
java.awt.geom.Path2D$Float.needRoom (boolean, int) 45,2 ms (0,7 %) 45,2 ms
(2,9 %) 76,7 ms (0,1 %) 76,7 ms (0,1 %) 30
java.util.Arrays.copyOf (float[], int) 21,9 ms (0,3 %) 21,9 ms (1,4 %) 23,0
ms (0 %) 23,0 ms (0 %) 28
sun.java2d.xr.GrowableIntArray.growArray () 20,5 ms (0,3 %) 20,5 ms
(1,3 %) 21,0
ms (0 %) 21,0 ms (0 %) 4
sun.java2d.loops.ProcessPath$DrawProcessHandler.PROCESS_LINE (int, int,
int, int, boolean, int[]) 10,3 ms (0,2 %) 10,3 ms (0,7 %) 716 ms (0,8 %) 716
ms (1,3 %) 391
Peter, what is your hardware & OS info ?
Laurent
PS: I made few modifs in your code:
diff --git a/src/polylinetest/Canvas.java b/src/polylinetest/Canvas.java
index 8aad48c..a355e18 100644
--- a/src/polylinetest/Canvas.java
+++ b/src/polylinetest/Canvas.java
@@ -1,17 +1,26 @@
package polylinetest;
+import java.awt.Color;
+import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.Timer;
-public class Canvas extends JComponent {
+public class Canvas extends JPanel {
public static int SIZEGRADE = 16;
public Canvas() {
+ super();
+ setPreferredSize(new Dimension(300, 200));
+ setBackground(Color.WHITE);
+
Random rnd = new Random();
int len = 1 << SIZEGRADE;
xs = new int[len];
@@ -20,6 +29,19 @@ public class Canvas extends JComponent {
xs[i] = rnd.nextInt(640);
ys[i] = rnd.nextInt(480);
}
+ final Timer t = new Timer(100, new ActionListener() {
+ int count = 0;
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ repaint();
+ count++;
+ if (count > 20) {
+ System.exit(0);
+ }
+ }
+ });
+ t.setRepeats(true);
+ t.start();
}
@Override
diff --git a/src/polylinetest/PolylineTest.java
b/src/polylinetest/PolylineTest.java
index 61c9e10..636c3b7 100644
--- a/src/polylinetest/PolylineTest.java
+++ b/src/polylinetest/PolylineTest.java
@@ -1,14 +1,29 @@
package polylinetest;
+import java.awt.BorderLayout;
import javax.swing.JFrame;
+import javax.swing.JPanel;
public class PolylineTest {
+
public static void main(String[] args) {
- JFrame frame = new JFrame("polyline test");
- frame.setSize(640, 480);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().add(new Canvas());
- javax.swing.SwingUtilities.invokeLater(() ->
frame.setVisible(true));
+ System.out.println("Java: "+System.getProperty("java.version") + "
" + System.getProperty("java.vm.version"));
+
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ JFrame frame = new JFrame("polyline test");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.add(new Canvas(), BorderLayout.CENTER);
+
+ frame.getContentPane().add(panel);
+
+ frame.pack();
+ frame.setVisible(true);
+ }
+ });
}
-
+
}
Le mar. 9 oct. 2018 à 15:29, Peter Hull <peterhull90 at gmail.com> a écrit :
> I posted this message first on Java Discuss and was asked to file a Java
> bug. It was also suggested I post it here for discussion.
>
> I've recently started using Java 11 and noticed that drawPolyline is
> much slower on my PC than it was on Java 8.
> Example, simplified code:
> @Override
> protected void paintComponent(Graphics g) {
> super.paintComponent(g);
> Graphics2D graphics = (Graphics2D) g;
> long starttime = System.nanoTime();
> graphics.drawPolyline(xs, ys, xs.length);
> long endtime = System.nanoTime();
> Logger.getLogger(this.getClass().getName()).log(Level.INFO,
> "Paint Time: {0}s", (double)(endtime-starttime) / 1.0e9);
> }
> where xs[] and ys[] are large (65536 points) integer arrays. On Java 8 I
> get a paint time of 0.025s and on Java 11 it is 25s, i.e. factor of 1000.
>
> This may be related to JEP263 (HiDPI)
>
> I've got a recent Core i7 processor with Intel graphics, running Windows
> 10.
>
> With VisualVM I can see that all the time goes in drawPolyline, I can't
> get any more detail than that.
>
> I have done some experimentation with RenderingHints but nothing makes the
> JDK11 go as fast as JDK8.
>
> Is there anything else I can try to either improve matters or to provide a
> clearer idea of why there is such a difference?
>
> I have a self-contained NetBeans project if anyone wants to try to see
> they can reproduce this.
> https://github.com/pedro-w/PolylineTest.git
>
> Thanks,
> Peter
>
>
> Versions:
> openjdk version "11" 2018-09-25
> OpenJDK Runtime Environment 18.9 (build 11+28)
> OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
>
> openjdk version "1.8.0-adoptopenjdk"
> OpenJDK Runtime Environment (build
> 1.8.0-adoptopenjdk-_2018_05_19_00_59-b00)
> OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)
>
>
--
--
Laurent Bourgès
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20181009/d5b6a398/attachment-0001.html>
More information about the 2d-dev
mailing list