Canvas initial delay issue

Jim Graham james.graham at oracle.com
Mon May 12 21:17:19 UTC 2014


This is likely due to growing the command buffer which was done linearly 
at one point (probably still done that way in 2.2), but is now 
exponential in 8.0.  The first render time is nearly instantaneous in 
8.0, but takes a long time as you found when I try it with one of my old 
2.x builds...

			...jim

On 5/12/14 8:40 AM, Renato Rodrigues wrote:
> Hi all,
>
> I'm trying to convert some Java2D code to JavaFX and I'm stuck with an
> issue regarding the performance of the JavaFX Canvas. At some point, I'll
> have to draw thousands of small circles on the screen.
>
> My problem is on the first drawing, on which my code takes a lot of time to
> execute. But if I have to perform a second drawing, it takes only a
> fraction of the time to draw (it is at least 10 times faster).
>
> Is there anything I'm doing wrong? Is there any way to prevent that initial
> delay?
>
> I wrote this code to test it. In this code I draw 500,000 circles at random
> positions on a 1000 x 1000 canvas (built previously). I linked this code to
> a button click event, and on the first time I click it takes 10 seconds to
> execute. But if I just click again, it takes only 0.025 seconds.
>
> private void paintCanvas() {
>      long initTime = System.currentTimeMillis();
>
>      GraphicsContext cg = canvas.getGraphicsContext2D();
>      cg.setFill(Color.WHITE);
>      cg.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
>      cg.setFill(Color.rgb(0, 0, 0, 0.1));
>
>      Random rand = new Random();
>      for (int i = 0; i < 500000; i++) {
>          cg.fillOval(1000 * rand.nextFloat(), 1000 * rand.nextFloat(), 2, 2);
>      }
>
>      long endTime = System.currentTimeMillis();
>      System.out.println("Time spent on drawing:" + (endTime -
> initTime)/1000.0f);        }
>
>
> Can anyone help me to understand the reason of this initial paint delay?
>
> Thanks in advance,
> Renato.
>


More information about the openjfx-dev mailing list