Skip to main content

Observing slower painting on 1.6?

1 reply [Last post]
gwampole
Offline
Joined: 2005-02-15

Hello,

I have a control that allows a child component to be expanded and hidden from view using an animated effect. Think of opening and closing a drawer from your desk.

Anyway, the part of the software that creates the animation effect looks pretty much like this:

<br />
Rectangle bounds = Bounds of component to be animated, initially collapsed (width = 0)<br />
JComponent parent = The parent of the animated component<br />
Graphics2D g = (Graphics2D)parent.getGraphics().create();</p>
<p>while ( animating )<br />
{<br />
    long start = System.currentTimeMillis();<br />
    g.fill( bounds );<br />
    System.err.println( "fill " + bounds + ": " +<br />
        ( System.currentTimeMillis() - start ) + " ms" );</p>
<p>    if ( expanding )<br />
    {<br />
        bounds.width = bounds.width + 15; /* Creates animating effect */<br />
    }<br />
    else /* for collapsing */<br />
    {<br />
        Rectangle prevBounds = new Rectangle( bounds );</p>
<p>        bounds.width = bounds.width - 15;</p>
<p>        Area bigArea = new Area( prevBounds );<br />
        bigArea.subtract( new Area( bounds ) );</p>
<p>        start = System.currentTimeMillis();<br />
        parent.paintImmediately( bigArea.getBounds() );<br />
        System.err.println( "paintImmediately: " +<br />
            ( System.currentTimeMillis() - start ) + " ms" );<br />
    }<br />
}<br />

After all this, the animated component is added to the parent at bounds if expanding or removed prior to this if collapsing.

My question relates to the performance of these operations. On JavaSE 1.5.0_08, the lines I have added that print the number of milliseconds taken in the calls to fill and paintImmediately produce the following output:
[pre]
fill java.awt.Rectangle[x=0,y=277,width=0,height=516]: 2 ms
fill java.awt.Rectangle[x=0,y=277,width=15,height=516]: 0 ms
fill java.awt.Rectangle[x=0,y=277,width=30,height=516]: 1 ms
fill java.awt.Rectangle[x=0,y=277,width=45,height=516]: 0 ms
... Now collapsing
paintImmediately: 4 ms
fill java.awt.Rectangle[x=0,y=277,width=442,height=516]: 0 ms
paintImmediately: 11 ms
fill java.awt.Rectangle[x=0,y=277,width=427,height=516]: 0 ms
paintImmediately: 2 ms
fill java.awt.Rectangle[x=0,y=277,width=412,height=516]: 1 ms
paintImmediately: 2 ms
[/pre]
And that looks pretty good! However, running with 1.6.0 gives me this output:
[pre]
fill java.awt.Rectangle[x=0,y=277,width=0,height=516]: 2 ms
fill java.awt.Rectangle[x=0,y=277,width=15,height=516]: 19 ms
fill java.awt.Rectangle[x=0,y=277,width=30,height=516]: 20 ms
fill java.awt.Rectangle[x=0,y=277,width=45,height=516]: 20 ms
... Now collapsing
paintImmediately: 6 ms
fill java.awt.Rectangle[x=0,y=277,width=442,height=516]: 16 ms
paintImmediately: 3 ms
fill java.awt.Rectangle[x=0,y=277,width=427,height=516]: 24 ms
paintImmediately: 4 ms
fill java.awt.Rectangle[x=0,y=277,width=412,height=516]: 20 ms
paintImmediately: 4 ms
[/pre]
Which is clearly much slower, at least in the fill operation. So, what could be the reason for this?

My platform is a Blade 2500 (Silver) 2xSPARC IIIi, 4GB running Solaris 8_04. My (perhaps) relevant JVM flags are:
[pre]
-Xms1536m
-Xmx2048m
-Xconcurrentio
-XX:+UseConcMarkSweepGC
-d64
-Dawt.toolkit=sun.awt.X11.XToolkit
[/pre]

Any advice or suggestions would be greatly appreciated!

Thanks,
-Garrett Wampole

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Chris Campbell

Hi Garrett,

It's really tough to tell what could be going on without having a
complete testcase to try out. Since in this case it looks like
Graphics2D.fill(Rectangle) is slower in 1.6 than in 1.5, perhaps you
could extract a small microbenchmark that times only that particular
operation, and see if there's a difference between the two releases.
For example, it could be as simple as (in your paintComponent() method):

Rectangle bounds = ...;
long start = System.currentTimeMillis();
for (int i = 0; i < numreps; i++) {
g.fill(bounds);
}
getToolkit().sync();
long end = System.currentTimeMillis();
System.err.println("fill " + bounds + ": " +
((end - start) / numreps) + " avg ms");

Is there any difference between 1.5 and 1.6 if you enable tracing?
-Dsun.java2d.trace=log

And finally, I assume you're displaying to a local Xserver in both
cases?

Thanks,
Chris

On Jan 16, 2007, at 12:07 PM, java2d@javadesktop.org wrote:
> Hello,
>
> I have a control that allows a child component to be expanded and
> hidden from view using an animated effect. Think of opening and
> closing a drawer from your desk.
>
> Anyway, the part of the software that creates the animation effect
> looks pretty much like this:
> [code]
> Rectangle bounds = [i]Bounds of component to be animated, initially
> collapsed (width = 0)[/i]
> JComponent parent = [i]The parent of the animated component[/i]
> Graphics2D g = (Graphics2D)parent.getGraphics().create();
>
> while ( animating )
> {
> long start = System.currentTimeMillis();
> g.fill( bounds );
> System.err.println( "fill " + bounds + ": " +
> ( System.currentTimeMillis() - start ) + " ms" );
>
> if ( expanding )
> {
> bounds.width = bounds.width + 15; /* Creates animating
> effect */
> }
> else /* for collapsing */
> {
> Rectangle prevBounds = new Rectangle( bounds );
>
> bounds.width = bounds.width - 15;
>
> Area bigArea = new Area( prevBounds );
> bigArea.subtract( new Area( bounds ) );
>
> start = System.currentTimeMillis();
> parent.paintImmediately( bigArea.getBounds() );
> System.err.println( "paintImmediately: " +
> ( System.currentTimeMillis() - start ) + " ms" );
> }
> }
> [/code]
> After all this, the [i]animated[/i] component is added to the
> parent at [i]bounds[/i] if expanding or removed prior to this if
> collapsing.
>
> My question relates to the performance of these operations. On
> JavaSE 1.5.0_08, the lines I have added that print the number of
> milliseconds taken in the calls to [i]fill[/i] and [i]
> paintImmediately[/i] produce the following output:
> [pre]
> fill java.awt.Rectangle[x=0,y=277,width=0,height=516]: 2 ms
> fill java.awt.Rectangle[x=0,y=277,width=15,height=516]: 0 ms
> fill java.awt.Rectangle[x=0,y=277,width=30,height=516]: 1 ms
> fill java.awt.Rectangle[x=0,y=277,width=45,height=516]: 0 ms
> ... Now collapsing
> paintImmediately: 4 ms
> fill java.awt.Rectangle[x=0,y=277,width=442,height=516]: 0 ms
> paintImmediately: 11 ms
> fill java.awt.Rectangle[x=0,y=277,width=427,height=516]: 0 ms
> paintImmediately: 2 ms
> fill java.awt.Rectangle[x=0,y=277,width=412,height=516]: 1 ms
> paintImmediately: 2 ms
> [/pre]
> And that looks pretty good! However, running with 1.6.0 gives me
> this output:
> [pre]
> fill java.awt.Rectangle[x=0,y=277,width=0,height=516]: 2 ms
> fill java.awt.Rectangle[x=0,y=277,width=15,height=516]: 19 ms
> fill java.awt.Rectangle[x=0,y=277,width=30,height=516]: 20 ms
> fill java.awt.Rectangle[x=0,y=277,width=45,height=516]: 20 ms
> ... Now collapsing
> paintImmediately: 6 ms
> fill java.awt.Rectangle[x=0,y=277,width=442,height=516]: 16 ms
> paintImmediately: 3 ms
> fill java.awt.Rectangle[x=0,y=277,width=427,height=516]: 24 ms
> paintImmediately: 4 ms
> fill java.awt.Rectangle[x=0,y=277,width=412,height=516]: 20 ms
> paintImmediately: 4 ms
> [/pre]
> Which is clearly much slower, at least in the [i]fill[/i]
> operation. So, what could be the reason for this?
>
> My platform is a Blade 2500 (Silver) 2xSPARC IIIi, 4GB running
> Solaris 8_04. My (perhaps) relevant JVM flags are:
> [pre]
> -Xms1536m
> -Xmx2048m
> -Xconcurrentio
> -XX:+UseConcMarkSweepGC
> -d64
> -Dawt.toolkit=sun.awt.X11.XToolkit
> [/pre]
>
> Any advice or suggestions would be greatly appreciated!
>
> Thanks,
> -Garrett Wampole
> [Message sent by forum member 'gwampole' (gwampole)]
>
> http://forums.java.net/jive/thread.jspa?messageID=195131
>
> ======================================================================
> =====
> To unsubscribe, send email to listserv@java.sun.com and include in
> the body
> of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".