Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Java3D start faster?

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.

like image 869
Michael Myers Avatar asked Feb 03 '09 17:02

Michael Myers


1 Answers

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.

like image 108
Michael Myers Avatar answered Oct 09 '22 17:10

Michael Myers