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

Performance problem with dashed lines



    • Bug
    • Status: Open
    • P4
    • Resolution: Unresolved
    • 7, 17, 18
    • tbd
    • client-libs
    • None
    • 2d
    • generic
    • generic


      In some cases we have poor performance with rendering of dashed lines. Here is the report from the java2d mailing list:

      Hi folks,

      I've found what seems like a bug in the java2d drawing code. I've
      included a simple test application, at the end of this email, that
      demonstrates the problem. It involves drawing dashed lines whose
      ratio of line length to dash length is very large. I've tested it in
      both java 1.4.2 and java 1.5 and found the problem in both cases.

      Here are some results of my tests that demonstrate the issue.

      Drawing a solid line seems fine no matter what the length...

      ken@saturn> time java -cp . DrawDash 0 10000000

      real 0m0.980s
      user 0m0.752s
      sys 0m0.052s

      ...However, when we add a dash to this long line it suddenly takes
      much longer to draw...

      ken@saturn> time java -cp . DrawDash 5

      real 0m10.262s
      user 0m9.865s
      sys 0m0.080s

      ...however, if we simply drop the length of the line down by a factor
      of 10 we are back to a reasonable length of time ...

      ken@saturn> time java -cp . DrawDash 5 1000000

      real 0m1.317s
      user 0m1.212s
      sys 0m0.016s

      ... The problem seems to be more based upon the ratio of the dash length to the
      line length as evidenced by the following set of results. First, this
      short line length with this incredibly short dash length is mostly

      ken@saturn> time java -cp . DrawDash .0005 100

      real 0m2.426s
      user 0m2.220s
      sys 0m0.044s

      ...while these two, with a dash/length ratio 1/10th of that above, I
      had to kill because they were taking longer than 2 minutes!...

      time java -cp . DrawDash .0005 1000
      time java -cp . DrawDash .00005 100

      ...which seems to suggest that it is not entirely based upon the ratio
      since if that were the case they should take around 10 or 11 seconds
      as the one above with the same ratio. However, they take much longer
      than that. Maybe they will never finish!

      But, anyway, something is going on that it seems should be easily
      fixed. Anyone have any ideas?



      Here is the code for my tests...

      import javax.swing.JDialog;
      import java.awt.BasicStroke;
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Graphics2D;
      import java.awt.geom.Line2D;

      public class DrawDash
          public static void main( String[] args )
              double lineSize = 1000.;
              float dashLength = 10;

              if ( args.length >= 1 )
                  dashLength = Float.parseFloat( args[0] );

              if ( args.length >= 2 )
                  lineSize = Double.parseDouble( args[1] );

              JDialog dialog = new JDialog();
              dialog.setSize( new Dimension( 800, 800 ) );

              Graphics2D graphics = (Graphics2D) dialog.getGraphics();
              graphics.setPaint( Color.RED );

              if ( dashLength > 0 )
                  float[] dashArray = new float[]{ dashLength, dashLength };

                  BasicStroke stroke;
                  stroke = new BasicStroke( 1,
                                            0 );
                  graphics.setStroke( stroke );

              graphics.draw( new Line2D.Double( -lineSize,
                                                lineSize ) );

              System.exit( 0 );




            Unassigned Unassigned
            avu Alexey Ushakov
            0 Vote for this issue
            2 Start watching this issue