[SOLVED] Bad Pooling Performance thanks to set_deferred("process_mode", ...)

Godot Version

4.2.2

Question & Answer

I just want to document this.

I was following this video to pool my objects. In addition, I wanted to be smart (it was NOT done like this in the Video!) and I thought, that I’d better enable/disable the process of my pooled objects to make sure they don’t eat up performance when being in the pool (and not used at the moment).

This was a mistake.

I did this when I took an object out of the pool (and set the process_mode to _DISABLED when I returned the object).

my_object.set_deferred("process_mode", Node.PROCESS_MODE_INHERIT)

This is what happened when I spawned my enemies (always tried to keep ~100 in the game):
image

And this is my performance when I commented out the my_object.set_deferred("process_mode", ...) commands:

image

I’m not sure why it’s so expensive to enable/disable the node process mode, but 20 FPS is quite a lot.

If you are interested, here is the full movie where I look at my game, change the code and look at it again: https://youtu.be/DDGGElMgURk

The issue is more likely that changing the process mode propagates to all the affected child nodes and that can cause a lot of updates depending on what nodes you used to build your enemies. E.g. physics nodes that can not process get removed from the physics space and that can cost a lot of performance. When the physics space is already struggling due to an inflated number of objects in very small proximity the internal physics tree sync alone will be costly.

1 Like