We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › jumpy / pause-y rendering -- GC
Page Index Toggle Pages: 1
jumpy / pause-y rendering -- GC? (Read 525 times)
jumpy / pause-y rendering -- GC?
Feb 24th, 2010, 10:35pm
 
this post got a little long, so i'll preface with a summary:
looks like the garbage collector is (periodically) impacting rendering performance, and i'm looking for a way to tame it.

for the curious, read on...

i'm writing an application that textures a bunch of polys (drawn via a series of begin/endShape() + vertex() calls) with a Capture.  i've tuned it to the point that playback is pretty smooth, except that every couple seconds the screen pauses for a frame or two.

i've noticed:
this does not happen when using a fill() instead of a texture();
decreasing the number of polys increases the time between pauses to 3-4 seconds, but does not eliminate them;
decreasing the Capture resolution (from 320x240 -> 160x120) increases the time between pauses to 8-10 seconds, but does not eliminate them.

i'm guessing this has something to do with RAM allocation, but it's a total guess.  any thoughts on what might be going on here, and how to clear it up?  is it possible to....

hm, searched around for more on managing memory, and found more info here:
http://processing.org/reference/troubleshooting/#memory

so, i tried printing out allocated, free, and maximum.  and what i see is that i run for ~25 frames with a lot of free memory, the number drops a bit (but is still ample) for ~10 frames, then the display hiccups as described above, and free memory jumps back up to the previous value.

which looks like the garbage collector is running, and affecting rendering....

i know very little about the JVM GC; most of what i know about GC comes from AVM (flash).  any ideas on tricks to smooth things out?  or thoughts about the accuracy of my analysis?

thanks!
Re: jumpy / pause-y rendering -- GC?
Reply #1 - Feb 24th, 2010, 10:50pm
 
I am not a specialist of garbage collection. Java's one is actually... Java's ones, ie. I think there are several GC algorithms. You can choose which one when running Java applications from the command line... Choosing the right one can be delicate, and they come with a bunch of options, so fine tuning this can be time consuming and need a good amount of doc researches...
As you guessed, if you create less objects, or using less memory, decrease the need to GC. That's why libraries like JBox2D attempts to avoid creating lot of short lived objects (eg. a vector to return a couple of values).
Better than a bunch of println, you can use JVisualVM, a tool of Sun shipped with their JDK, but also available independently: it allows to monitor memory, CPU and GC.
Re: jumpy / pause-y rendering -- GC?
Reply #2 - Feb 27th, 2010, 12:48pm
 
so, this thread:
http://processing.org/discourse/yabb2/num_1234194779.html#9

led me to this article:
http://www.petefreitag.com/articles/gctuning/

which led me, ultimately, to the following workaround:
use the command-line switch
-XX:+AggressiveHeap

Aggressive Heap aims to make the most of heap memory, and can often lead to out of memory errors or, alternately, insanely-long GC times (5-10 seconds) after a long time with no GC at all.

my solution -- call System.gc() on a timer (every 10 seconds or so).  the first few GC calls in a session may be a bit heavy, but it seems the JVM gets better at allocating memory after a bit, and the GC times eventually get down to ~.05 seconds.  i can deal with a one-frame pause every 10 seconds.

so, yeah, probably not the best solution, but it seems to work...still have to let it run overnight and see if everything is peachy in the morning.
Page Index Toggle Pages: 1