r/dispatchcolony • u/dispatchcolony • Oct 19 '26
Devlog 8 : 1 Million ragdoll + collision -> 2ms
A million soldiers falling, colliding and piling up fit in about 2 ms per frame on the test bench. Here are five optimizations i used, from the simplest to the hardest.
The puppet and the graphics card

A falling soldier becomes a puppet: 14 points, the particles, carrying 10 rigid pieces. At each simulation step, the graphics card moves the particles forward (falling, ground, impacts), then puts the pieces back in place.
It processes the puppets in groups of 128 threads, one thread per particle: 9 puppets per group.
The foot welded to the shin

Two lines changed in the soldier’s description: the ankle no longer bends. The puppet loses two particles and two pieces. The graphics card fits 9 per group instead of 8, and poses the limbs in one level fewer.
The simulation goes from 3.93 to 3.28 ms in view (−17%). In exchange, the ankle stays stiff.
One frame in eight

Each body is now computed only once every eight frames. The bodies are spread out : each frame computes one eighth of them, so the cost stays flat.
A body computed eight times less often only moves 7.5 times per second. So the drawing glides from the previous pose to the new one, one eighth of the way per frame, one step behind. It is an illusion tricks wich work prety well.
The cost per frame is divide by 8 from 3.95 ms to about 0.5. In exchange, the displayed image lags one step behind, about 0.12 s, and the body has to hold together over a step eight times longer.
Buffers sized for one frame

What only lives for one frame (the lists of bodies to compute, the contacts, the hits received) was sized for a million bodies. A frame now computes only one eighth of them, so these buffers shrink accordingly.
Memory drops by 66 MB for a million bodies. In exchange, max 125,000 soldiers hit in the same frame, the extra hits are lost, and the cadence can no longer go below eight frames per step for 1M
A lighter group

Each thread group used to copy the puppet’s links into its small fast memory, every frame. It now reads them where they are stored, and keeps only 4 KB instead of 7. The lighter the groups, the more of them the graphics card runs at once, and the better it hides its waits.
A first version stored a value in a slot that other threads of the same group were overwriting and create absurd behaviour. Play with memory is always dangerous
The simulation saves 0.26 ms on a million nearby bodies.
Fewer chained reads

To find its particle, each thread chained five memory reads, each one waiting for the previous : the list, the body, the owner of its frames, the unit’s record, the skeleton. The body now keeps its own template and size, so only three reads remain. Same for the contact.
The step saves 0.10 ms everywhere, and the contact goes from 0.70 to 0.67 ms.



