Retiring the canvas renderer
A port that was measured, declined, and eventually shipped. The interesting part is not that the decision changed — it is why both decisions were right.
Published · 7 minute read
Canvas 2D was not an aesthetic choice. NanoGenesis draws a projection of a 10 Hz simulation: sixty element sources on four orbit rings, up to a hundred building types and eight hundred instances, a swarm of bots carrying cargo, harvest particles, Dyson bands, and a camera that runs from 0.06× to 3.6×. None of that needs a scene graph. It needs a redraw.
That is the whole architectural argument, and it is why the first attempt to replace the renderer was declined. The second attempt succeeded because it changed the art instead. This is the record of both.
What the renderer actually was
At spike time the playfield was components/SwarmCanvas.tsx, 1,860 lines.
Roughly 667 of those were the React wrapper, RAF loop and pointer input; 215 were DOM
hover cards; 855 were the draw helpers — rings, elements, buildings, bots, star and Dyson,
icons, ghosts and pods; 123 were shared helpers and types. The only engine-bound code was
the drawing itself.
Everything the drawing needed was already pure and unit-tested: camera.ts at
132 lines, gestures.ts at 53, cluster.ts at 101,
pods.ts at 46, dyson.ts at 395. The simulation lived in
logistics.ts (1,580 lines) and a 10 Hz tick. The renderer read a state ref,
noticed when a new simulation step landed, and interpolated
alpha = (ts - lastTickAt) / 100. It built a screen-space hit list during the
draw, and hitAt answered hover from it.
The spike: a faithful port, not a rewrite
The work lived on spike/pixi-engine behind a /spike route. It
was deliberately literal. The Pixi renderer was 1,767 lines, the React wrapper 468, and
the texture helpers 126: 2,361 lines against roughly 1,645 lines of loop, input and draw
in the shipped renderer. That is +43% code before reaching parity, and the spike still
had no focus panel, no Star-0 guide anchor, approximate glows and an unclipped pod fill.
It imported the untouched pure modules and reused CanvasHit as a type-only
import. It kept one requestAnimationFrame loop instead of adopting Pixi's
ticker, so the A/B comparison measured the same pacing architecture on both sides, and it
kept the same 10 Hz interpolation. It rendered every layer and kept the same camera rules.
What the numbers said
The fixture was the full unlock: star 9, sixty sources, a hundred building types, eight hundred instances, 1,040 bots, 1,440 particles, 6,550 sprites, 10,225 containers and 149 glyph textures. The environment was Windows 11, headless Chrome at 1422×728 CSS pixels and DPR 1, with WebGL provided by SwiftShader — a software rasteriser. Headless Chrome pauses RAF when the page is not visible, so frames were driven manually in synchronous loops of sixty with synthetic 16.7 ms timestamps. The numbers are JS/CPU time; paint and composite are excluded.
| Measurement | Median | p95 | Max |
|---|---|---|---|
| Canvas 2D — RAF callback (draw, hit list, camera) | 7.1 | 11.1 | 13.5 |
Pixi — scene sync only, app.render() skipped |
7.2 | 15.7 | 22.0 |
| Pixi — sync + render (SwiftShader) | 11.6 | 65.7 | 3,270 |
| Pixi — same, zoomed to 3.6× | 16.3 | 45.3 | 134.6 |
Read the first two rows together. Keeping the retained scene coherent cost as much as the entire canvas renderer cost to draw from scratch. The render half of the Pixi frame is SwiftShader-bound and should be discounted on real hardware; the sync half is not. On a real GPU the best case is rough parity, not a win — and there are now 10,225 containers with per-object lifecycle rules.
That lifecycle does not show up in a frame-time table. A tier change rebuilds an icon, a zoom cap rebuilds slots, a merge hides the landing instance, a star change recreates textures. Each rule is a place where the Pixi scene and the 10 Hz state can disagree; the canvas renderer could not disagree because it recomputed from state every frame.
The non-frame costs were real too: the lazy route added 6.51 kB to a 698.97 kB entry, thirteen engine chunks totalled 177.1 kB gzip, and the PWA precache grew from 844.3 KiB to 1,435.4 KiB. Page heap went from 77.1 MB to 111.2 MB with Pixi — about 34 MB extra, plus GPU textures the JS heap does not count.
The verdict
Stay on the hand-rolled Canvas 2D renderer, with a narrow "adopt-for-X" escape hatch. The port worked — same sources, buildings, bots and particles, same camera maths, same interpolation, byte-identical hit tests — but at the game's real object count it was not faster on the CPU, and it was a new source of bugs.
Pixi would only win if the port stopped being a faithful port: one
ParticleContainer for bots and particles, one Graphics per
background layer, no per-instance display objects, and art authored for that structure.
The spike said plainly that this was a rewrite, not a migration.
The record then reverses
The published game now runs Pixi 8 as its only playfield. It became the default in
v0.15.0, and the Canvas 2D renderer was removed in v0.15.1, "Clean Burn".
?pixi=canvas still selects Pixi's own Canvas 2D renderer on devices without
WebGL. The original verdict is preserved at the top of the spike document as the record,
not deleted.
The docs do not contain a decision memo explaining the reversal, and this note is not going to invent one. What they do contain is a second document describing a build that is not the spike's faithful port. Read it as the spike's objections being paid off rather than argued away:
-
Per-instance
Graphicsbecame baked Canvas 2D textures on sprites; oneGraphicsdisc per instance had caused a context loss roughly once a second on an Adreno GPU. -
Rings, bots and particles are culled with the canvas renderer's own
circleIntersectsRectand bot LOD, shared throughviewMath. -
The star is one shared definition in
game/starArt.ts, with textures cached by star identity; the Pixi chunk is lazy-loaded behind Suspense; mobile DPR is capped at 2× with MSAA off. - WebGL context loss gets a DOM overlay, a loss counter and a guarded reload instead of a blank canvas.
None of that makes the original measurement wrong. It makes the measured artefact different. The spike measured a literal port of a drawing program; the shipped renderer is a texture-and-culling renderer that happens to use Pixi. The first question — is a migration worth it? — got no. The second — is a rewrite worth it? — got yes, on different evidence.
That later evidence needs a caveat. The parity document reports a 1440p RTX 3080 run where the retired Canvas renderer measured 44 / 119 / 58 fps at default, zoom-in and overview, against Pixi at 87 / 117 / 120. It also notes that the Canvas row is a production build and the Pixi row is from the dev server, so it is not a controlled benchmark; Pixi is "at least as good", not proven faster by that table. The stronger evidence is a phone playtest: 45–55 fps in Chrome and Edge on a OnePlus 12R, around 30 fps in Firefox Android. The shipped build is the proof.
What we took away
Measure the scene you intend to ship, not the quickest port you can build. A faithful port estimates migration cost; it cannot decide whether a different architecture would be faster, because it preserves the old architecture. The spike said so itself: Pixi only wins if the port stops being a port. The engine is the easy part — camera, gestures, cluster, pods and Dyson maths stayed pure and tested through both attempts. What cost time was gradients, glyph atlases, dashed strokes, glows, DPR-correct texture baking and object lifecycle. Budget the assets.
Keep the renderer out of state. The engine read a state ref and wrote through the existing
actions; SAVE_VERSION never changed; rollback was a flag until the deletion.
That is what made it safe to be wrong twice. And state the limits of the measurement: the
spike's verdict was medium-confidence because the only GPU was SwiftShader, and the parity
build's best evidence is a phone. The canvas renderer is gone now, but the first
measurement was not overturned. It was outgrown.
The companion entry, Sixty elements, ordered by the stars, covers the economy this renderer draws: sixty sources across ten star eras, and the research contract that keeps them reachable.
Building something with a long operational life?
That is the kind of system we like to scope. Tell us what you're building and we'll tell you how we'd approach it.
Start a Conversation