"Garbage Collect States"--Finding the source of there being many

(Split off from this thread: The node-counts given by "analyze" and PStats )

Looking at PStats, it seems that I’m finding an awful lot of time in “garbageCollectStates”, and I’m hoping to find a way to reduce that time.

A call to “RenderState.getNumStates()” indicates that I have about 4000 states.

However, looking over the results of “RenderState.listStates(Notify.out())”, I get the impression that some of those states are on objects that aren’t visible–things like closed menus, and so on.

Putting the list-output into a spreadsheet, I see that major contributors to that number of states include TransparencyAttrib, DepthWriteAttrib, CullBinAttrib, CullFaceAttrib, DepthTestAttrib, ColorAttrib, and various ShaderAttribs. (The first two of those easily more than the others: both account for over a thousand entries, with the next (CullBinAttrib) accounting for around 750.)

That said, attempts to remove setting of transparency and depth-writing attribs have thus far yielded no apparent improvements in performance… (Otherwise I might be tempted to establish nodes for some of the more frequent uses of those attribs, and simply parent affected objects below those.)

Thinking more about the fact that some of the reported states are on objects that are hidden, let me ask: How do nodes that exist, but that are not currently part of the scene-graph (e.g. via having been detached), impact on state garbage collection?

I ask because, well, I do have a lot of such nodes–it allows me to flip between levels/areas relatively quickly.

But could it also be incurring significantly greater time in “garbageCollectStates”…?

[edit] It should perhaps be noted that setting “state-cache 0” and “transform-cache 0” (via calls to “loadPrcFileData”) produced little benefit.

They just do, the state cache stores all states in existence including those on hidden nodes. The garbage collection is part of the state cache management and the number of nodes that are in view has no impact on it.

You should not see any time in garbageCollectStates if you disable garbage-collect-states in Config.prc or the state cache altogether.

Aah, I see. I had thought that nodes not currently being rendered would have little impact!

I may have to re-think some of how I’m handling my “worlds”, then. But in all fairness, that may be called for anyway.

If I set “garbage-collect-states” to “0”, I do indeed see no time in “garbageCollectStates”–although it looks like the time just ends up elsewhere. :/

If I set “state-cache” to “0”, the time spent in “garbageCollectStates” reduces, but doesn’t go away.

Hum. My guess at the moment is that I have some fundamental problem with the way that I’m handling my scene…