Limiting the number of spatials added to a scene in any given frame

@pspeed I think this question is specifically targeted towards you, as I believe I saw the suggestion posted by you in a discussion about optimizing multithreading.

You mentioned limiting the number of spatials added to/removed from the scene during any one frame and I’m curious if you have any pointers about how to go about this. I haven’t put a lot of thought into it as of yet and I’m hoping with your input I won’t have to :slight_smile: Here be the scenario… perhaps you can point me in the right direction.

Here are those involved in the scenario:

1 control that manages updates to the scene and listens for updates from…

1 background thread that determines what is and is not within the defined radius of visible (this could be for terrain/vegetation/anything really). If new tiles/chunks/leafs/whatever are needed it creates them… if objects have moved from the visible radius, it marks them for removal and caches them until they are pushed from the stack or recycled and added back to the cache. Once a list of new/old chunks is produced, the thread notifies all listeners of any new available update.

X custom meshes for creation of whatever it is the manager is creating/updating/managing.

Where I’m struggling with this is the following:

The update list usually consisted of multiple tiles/chunks/leafs to be added as well as multiple tiles/chunks/leafs that have been flagged for removal. What would be the best way (for that matter any way) of breaking up the adding/removing of these new tiles/chunks/leafs over multiple frames? I’ve kicked around a few ideas (in my single-celled organism of a brain), however, each seems to be problematic and I’m not really sure where/how/who/why/when to start.

Any help/suggestions/kick in the right direction would be greatly appreciated.

Easiest way: one Callable or Callable-like thing per tile/chunk/leaf. Add them to a ConcurrentLinkedQueue when a change to the scene graph is needed (add/update/remove/whatever). In update, pull one item off per frame and execute it.

1 Like