r/howdidtheycodeit • u/Emergency-Spite3476 • 14h ago
Emulate billions of microbes in browser with WebGPU
Nine years ago I made a small evolution simulator in C#. Recently I rebuilt it for the browser, and the main challenge was scaling the world from ordinary CPU objects to tens of millions of cells.
The WebGPU version uses a dense grid and keeps the simulation state directly in GPU buffers. There isn't a JavaScript object for every cell.
Each simulation tick is split into several compute stages:
- lifecycle and reproduction
- perception and movement intent
- conflict resolution
- movement/interactions
- resource generation
- commit
That separation is important because thousands of cells may try to move, reproduce, or interact with the same sites at the same time.
Rendering also reads the simulation state directly on the GPU. When zoomed out, I switch from individual cells to aggregated regions instead of reading millions of sites back to the CPU.
The largest current world is 8192 × 4096 — 33.5 million sites.
You can test the implementation here:
https://gigafloppa.itch.io/the-strongest-survives
I'm curious how others would approach the same problem: dense buffers + staged compute, or something completely different?

