Re: high memory consumption (IntIntHashMap)

Posted by cowboy on
URL: https://forum.jogamp.org/high-memory-consumption-IntIntHashMap-tp2626543p4032799.html

I believe this is allocating lots of memory because of TextRenderer calling glPushClientAttrib() and glPopClientAttrib(), maybe twice each in fact.

On my program, I render 50-80 per frame maybe and it allocates 20MB per second at 20 FPS, which is crazy.

It calls these as it does VBO rendering. If you adapt the code and take these calls out my RAM usage goes down to < 1 MB per second, which will just be general other random objects being allocated.

The push/pop methods appear to be called only to restore the VBO state, however, the TextRenderer class unbinds its VBO after use each time, so its merely called to maintain some vertex / tex coord pointers, which generally you reset when you bind your own VBO anyway, and generally you wouldn't have an external VBO bound when calling the text renderer drawing anyway.

I see why its there for general purpose but its a killer on memory allocation, esp for so few calls even per frame 20MB is pretty wild. Also, it still push/pops even if you disable VBO usage with setUseVertexArrays(false) which doesn't seem like its even needed after that is set to false.

Additionally it pushes all attrib bits, does it need to push the pixel store bit along with the vertex array bit, I'm unsure but doubt it. I tested disabling each actually and pixel store bit accounts for maybe 15/20 mb of the allocation and the vertex array bit 5mb per second.

Anyway, hope this helps if people stumble across it. I'd suggest take an adapt the code to comment those out if you get similar and understand it may change some VBO states, but it does unbind the VBO it uses (and therefore maybe yours if you had one set) and ideally you could use it to create your own cached images of the font strings and use them as image renders, or code your own manually is even better. With these calls removed its quite usable and does render quickly as it does a good caching job of generic strings in general, and perhaps the poor performance of glPushClientAttrib / glPopClientAttrib is implementation specific, but these things are nowadays deprecated/avoided with handling your own states, and appear to be poor here.

Another thing to note is that TextRenderer uses TextureRenderer which has some glPushAttrib/glPopAttrib calls, they're not severe on the memory allocation but also not so optimal as your own state handling so again, something to watch for high performance.

Hope this helps!