Public: anyone can read this; the crew can change it.
forked from trevato/cs
What each part of the engine costs, measured: the guide says what importing a group adds to a bundle #260
Check · Review · Land · Live done — Landed and live in production.
`scripts/cost.ts` measures what each group behind the engine's door adds to a bundle: for every group `src/engine/index.ts` exports it generates a tiny entry that imports exactly that group and uses every name in it, bundles it with the settings `scripts/build.ts` gives a game — browser, minified, esm — and weighs the output raw and gzipped at level 9, the ruler the ceilings in `src/games.ts` alre…
shipped production is serving it deploy ae07c2d
Sign in to join this conversation.
new above
offline
scripts/cost.tsmeasures what each group behind the engine's door adds to a bundle: for every groupsrc/engine/index.tsexports it generates a tiny entry that imports exactly that group and uses every name in it, bundles it with the settingsscripts/build.tsgives a game — browser, minified, esm — and weighs the output raw and gzipped at level 9, the ruler the ceilings insrc/games.tsalready use. Groups are not independent, so each row also names the modules that came along and how many of the bundle's bytes are theirs, read off the build's source map rather than off the import lines: a module the bundler loaded and then shook away is charged to nobody, which is what makes "the range ships none of the WebGL" a number instead of a claim.The lines land in
src/engine/GUIDE.mdunder each group's heading (Weight: 7.4 kB raw, 3.1 kB gzipped — including math, which comes with it.), with the whole door's number under the section heading and a short preamble saying how they were measured and what they are careful about.scripts/cost.test.tsmeasures again on every run: every group has a line, every line is under a heading that is a group, the numbers are within a tenth — or 100 bytes, the page's own resolution, whichever is wider, which is the rounding the page does — and the list of modules a group brings along matches exactly. I checked both rules bite by editing the page and watching them fail.Two things worth looking at. First, the floor: importing the door at all costs 53 bytes, because
netallocates a scratchFloat32Arrayat module scope and a bundler may not drop an allocation it cannot prove nobody watches — sonetshows up in every bundle for 31 bytes, and a module counts as brought along only when it beats the floor by more than 16 bytes of minifier jitter. That is whymeshis alone andlearnis honestly charged 1,223 bytes ofnet. Second,rendererbrings onlymath:mesh,textureandscenereach it as types, so a game that draws pays their lines separately — 7.4 + 0.9 + 1.0 + 1.0 kB, which is the 11.4 kB the example gained in #222, and the guide says so in words rather than with an untested sum.What I chose not to do: no
--writemode that edits the guide (the script prints the lines with--guideand a person pastes them, likescripts/surface.ts --writeis a deliberate act), and I did not touchnet's module-scope allocation to flatten the floor — it is a hot-path scratch buffer and this issue is measurement, not surgery. No dependency, no bundle, no game changed: onlyGUIDE.md, the README's script list and the two new files inscripts/.bun run testis green (1140 tests).🤖 Generated with Claude Code
Closes #169