something is blocking my render loop

hello,

i am generating a lot of textures in a separate thread using apache’s batik library as the player moves around in the world. that means svg graphics get rasterized in this extra thread and when they are ready, they are loaded into openGL by calling TextureIO.newTexture( myTextureData );

unfortunately every couple of seconds i have a frame which lags for about a quarter of a second. this lagging looks terrible and destroys the smooth motion if the game.

now why can the renderloop be blocked when i do all the rasterization stuff in an extra thread?

thanks!

Are you sure the render loop is actually being blocked, rather than just yielding ever so often (if they’re at the same priority)? You might try running a profiler that shows what threads are going (the NetBeans profiler is really good at this)…

And are you using the Animator class? I’ve noticed the same thing on some of the demos (JGears in particular), where it suddenly pauses or at least slows down every few seconds… but I just assumed that was something about GLJPanels…

thanks for your reply.

it does not seem to depend on the thread priority. i have set the rasterizing thread to MIN_PRIORITY and it still happens.

yes, i am using animator, i have also set this
animator.setRunAsFastAsPossible(true);

is there an alternative to animator?

i am using eclipse, is there any good eclipse profiler for this situation? thanks!

edit: btw, i am also running a couple of other threads like for networking and these dont seem to be blocking the rendering at all.

Can you rule out garbage collection as a possible cause? Have you tried running with ‘-verbose:gc’ as a VM argument?

thank you very much!
the garbage collections seems to be the problem.
whenever i get a full GC like.

[Full GC 14227K->6914K(15424K), 0.0876396 secs]
i get a laggy frame afterwards.

anyone has a solution to this?

Avoid excessive heap allocations. Reuse objects where possible, and keep them in a pool. Best to write a class that manages these objects, especially in a multi-threaded environment.
Heap allocations themselves can be slow, so simply avoid them where you can.

Your best bet is to read the posts under ‘Performance Tuning’ on this site. Tuning the GC and this sort of thing are very popular among the readers of that board…

Matt.

manual pooling can often end up less efficient than just letting the jvm work its magic. But for some things, it’s absolutely awesome.

Just make sure to benchmark, benchmark, benchmark.

If it’s Batik that is the source of the garbage, what can you do then? I have a doubt about Batik being suitable for this kind of rendering…