The idle CPU mistery

Pushing “In Dead Company” AI to its limit I found a strange thing. When I spawn hundreds of combatants, frame rate drops. This is to be expected – there is a limit to how much computations CPU can do. Yet – my frame rate drops, but my CPU is not saturated. No single core is at 100%:

This slideshow requires JavaScript.

This is strange. I would expect one CPU to run at 100%. This means that this system is not CPU-bound – something else limits performance. But what? There is no I/O. Memory is hardly used.

Surely, I can rewrite all this code as native, or even use GPU acceleration, but there could be a simple limit I’m hitting. Even with it, engine reliably handles >200 characters in combat, but once I’ll figure it out I could get at least three times more.

This is a mystery to investigate.


And I have a result. It does seem that GDScript is being switched between cores. It takes full 100% of single core, but it is spread out over all of them by scheduler. It took a Linux machine with 4 cores to recognize this.

So, it seems I need to go for GPU acceleration or multi-threading if I want to pass 200 characters combat mark.

Leave a Reply