T-059: Step the world off the drawing thread, on the web and natively
Goal
In the viewer, the world and the picture share one thread. On the web that is the page's only thread, so the sim gets one core and every slow step is a dropped frame. Today 100,000 soup cells run a little under real time in desktop Chrome, and real physics will cost more. A phone manages far fewer.
Evan wants to open a link and be inside a living world, on his phone too. Give the sim its own thread or threads, so drawing stays smooth whatever the world costs, and the browser can use more than one core.
Scope
- Web. Decide between a Worker that owns the world and sends views to the page, real wasm threads (shared memory, which needs the site to send cross-origin isolation headers and a different build), or both in steps. Decide by building the smallest version of each that answers the question, and measure in Chrome and in Safari's engine. Whatever is chosen must still work where shared memory is not available.
- Native. The same separation: stepping never blocks a frame.
- The picture shows a consistent world: never half of one step and half of the next.
- The sim's promise holds: the same bits on any number of threads, native and web. A world
stepped in a Worker must match the same world stepped by
runner. - Playback controls, opening checkpoints, the "(behind)" readout and the stall watchdog keep working.
- No change to
crates/simunless there is no other way. If there is one, measure it withrunner bench.
Done when
- ☐ Frame rate on the web stays at the display's rate while a world too heavy for real
time is stepping, in Chrome and in Safari's engine. Numbers in
docs/VIEWER.md. - ☐ Steps per second on the web, before and after, for at least three world sizes, and how it scales with cores if threads are used.
- ☐ A world stepped N times on the web has the same checksum as
runnergives. - ☐ The phone stand-in (
node scripts/webfps.mjs --mobile --software) andscripts/webkit-probe.shboth pass. - ☐
docs/ARCHITECTURE.mdordocs/VIEWER.mdexplains the design and why.
Notes
- Suggested by the T-014 agent, with
docs/perf/IDEAS.md. - Cloudflare Pages can send the isolation headers from a
_headersfile. Check what that breaks (the/log/and/concepts/pages, loading checkpoints from other places) before relying on it. - Only one agent may compile Bevy at a time on this machine.
Added 2026-12-02: what the publish work changed (from T-020)
- The viewer now measures by itself when a world is too big for the device and says so in one notice (cells, steps per second, fraction of real time). Keep it truthful after stepping moves off the drawing thread.
- Automatic quality no longer lowers resolution when the sim, not the drawing, is what is slow. With stepping off the thread this distinction changes: check it again.
- A million-cell run opens in the browser at about 6 steps per second and 6 frames per second today, because one step blocks a frame. That is the number to beat.