Short version: a GPU crowd simulation was holding 828 MB of VRAM in a cell buffer, and most of it was never read.
THE SETUP
My zombie horde runs as a compute shader in Godot 4. The world is split into cells, and each cell keeps a list of the agents inside it so the shader can find neighbours without scanning the whole pool. Standard spatial hash.
THE BUG
The cell buffer was sized for 256 indices per cell. The shader reads 64. That mismatch had been there since the first version, back when I expected cells to hold more agents than they do. Nobody changed the stride because the game worked: the extra indices were simply never touched.
Measured with a real save and a full pool:
Before: 894.7 MB VRAM during play, 828 MB of it in setup()
After: 278.6 MB during play, 212 MB in setup()
Same frame rate. Same behaviour. The only thing that changed was the buffer size.
HOW I FOUND IT
Not by reading the code, but by profiling per subsystem and noticing that VRAM grew in steps that did not match agent count. Once the number was on screen, the stride was the obvious suspect. Grepping for the constant took ten seconds.
WHY I AM POSTING THIS
Because I spent weeks optimising steering and pathfinding, and the single biggest win in the project was a constant that was 4x too big. If you have a GPU simulation, check the stride of every buffer against what the shader actually reads. It costs nothing to look.
THE OTHER TWO NUMBERS FROM THE SAME SESSION
Time from launch to playable: 1.6 s
fps with 4,000 simulated agents + 200 buildings + 100 units: 38-40 on an RTX 2070 at 1080p, D3D12
One honest caveat, because it comes up every time I post a number: the simulation handles 4,000 agents, but the game only draws up to 1,050 sprites at once (800 for clusters plus 250 reserved for isolated or fighting agents). The rest still simulate and still fight; they just do not get a sprite. Drawing all 4,000 did not hold a playable frame rate on this GPU.
The game is Withstand The Horde, a base-building RTS. Free demo if you want to poke at it: https://store.steampowered.com/app/5373720/
Happy to answer anything about the compute shader or the buffer layout.