u/ElBranda

▲ 450 r/godot

I built a Native C++ Object Pool for Godot 4 to eliminate GC spikes (15k objects at 60FPS)

Hello everyone!

Like many of you working on object-heavy genres (bullet hells, massive swarms, dense particle logic), I kept hitting a wall with GDScript when handling thousands of concurrent entities. Frequent `instantiate()` and `queue_free()` calls inevitably trigger Godot’s Garbage Collector, causing those annoying micro-stutters that ruin fluid gameplay.

To solve this for my own projects, I went under the hood and wrote ZeroAllocPool, a native C++ GDExtension focused entirely on high-performance object pooling.

Technical Breakdown:

  • Architecture: It utilizes a Static Index Free-List Pool structure handled entirely in native C++.
  • Zero Runtime Allocations: Memory is allocated linearly upfront during initialization. No heap fragmentation during gameplay.
  • True O(1) Complexity: Grabbing an available object index via `obtain()` or returning it via `release()` takes constant time, completely bypassing sequential array lookups.
  • Production Ready: It compiles with clean separation between Debug (with boundary/error checks) and Release (optimized for maximum speed) binaries.

Performance Demo:

I put together a stress test spawning 15,000 active nodes. As you can see in the attached clip, standard high-frequency allocation causes the engine to chug down to ~20 FPS. Switching to the C++ native pool instantly stabilizes the frame rate back to a buttery-smooth, locked 60 FPS.

I’ve officially packaged it as a drop-in addon for Godot 4.6+. If your game is bottlenecked by dynamic memory management, feel free to check it out!

I would love to hear your thoughts on the architecture, or answer any questions about the GDExtension binding process!

Link: [https://elbranda.itch.io/zeroallocpool-native-c-performance-optimization-for-godot-4]

u/ElBranda — 13 hours ago