↑ ↓ to move · Enter to open

How the Lab's engine got 43% smaller

Portrait of Vincent MaderVincent Mader25 Nov 2026 · 2 min read

Every simulation in the Lab runs on the same engine: Rust, compiled to WebAssembly, loaded once and cached. Until this week a visitor downloaded 1.59 MB of it, 600 KB after compression. Two changes brought that down to 343 KB.

Text nobody downloaded it for

Each of the 98 simulations carries a long description: the history, the physics, what the presets show. The Lab pages need that text, but they get it when the site is built, not in the browser. The browser only ever asked the engine for parameters and presets. Still, every description sat in the WebAssembly file, more than 300 KB of text.

The fix is a Cargo feature. The descriptions now go through a small macro that keeps them only when the feature docs is on. The site generator turns it on, the browser build leaves it off, and the compiler drops the strings entirely. The engine went from 1.59 MB to 1.24 MB, and nothing on the pages changed.

Brotli without a brotli module

The server compressed everything on the fly with zstd or gzip. Brotli at its highest level compresses this kind of file about a quarter better, but it is far too slow to run per request, and neither the proxy nor the nginx image in front of the site has a brotli encoder.

It does not need one. The deploy script now writes a .br copy next to every CSS, JavaScript and WebAssembly file, once, at the highest level. nginx checks whether the browser accepts brotli, serves the copy with the right content type and encoding header, and the proxy passes an already encoded response through untouched. Browsers that do not ask for brotli still get gzip or zstd.

The result

BeforeAfter
Engine, uncompressed1.59 MB1.24 MB
Engine, as downloaded600 KB (gzip)343 KB (brotli)

That is 43% less to download before the first simulation starts, for one Cargo feature and a few lines of nginx configuration.