views:

246

answers:

1

My application takes several seconds to show the first window with a Canvas3D in it. I've profiled it and found that the bottleneck is in SimpleUniverse.getPreferredConfiguration(); the first call takes three or four seconds, and it must be called before the scene can be rendered.

I'm using the Direct3D renderer (-Dj3d.rend=d3d), because the OpenGL renderer crashes on my graphics card. I have an integrated ATI card running a single monitor.

+5  A: 

The reason for the slowdown is that GraphicsDevice.getConfigurations(), which is used by SimpleUniverse.getPreferredConfiguration(), is very slow on some systems. See this java.net forum thread, which links to this Java3D bug, which in turn links to this Sun bug:

The problem is that ::DescribePixelFormat Win32 call is slow - takes up to 60ms to complete. ...
With the suggested workaround (which elminats [sic] the offending win32 calls) the time is significantly improved (to, like, 0ms).

The workaround mentioned is to pass -Dsun.awt.nopixfmt=true to the JVM, which makes the underlying native code not call DescribePixelFormat.

This apparently is not a perfect solution:

... some applications which use OpenGL with Java may not work correctly.

But since I was using Direct3D anyway, it's not a problem. This cut 3.2 seconds off of the startup time.

Michael Myers
I just found this workaround yesterday, so I'm making a public record so I won't lose it again.
Michael Myers