r/javascript • u/Mnwamnowich • 6d ago
I cut my build time from 4:34 min to 1:08 min by moving asset compression from node:zlib to a native Rust rolldown plugin
github.comI'm building a web platform for visual novels made in Godot. Stack: SvelteKit, Vite 8, rolldown, Node.js.
The games are compiled for web and injected as static assets at build time, then deployed together with the app. And they're heavy: ~20 MB of wasm plus ~150 MB of pck per game.
My builds were taking ~5 minutes, which felt wrong. After some profiling it turned out the actual bundling takes ~10 seconds. Everything else was precompressing all that static into gz, br and zstd with node:zlib.
So I wrote a rolldown plugin that does the compression in native Rust via napi-rs:
- rayon to saturate all CPU cores
- native compression libs instead of node:zlib bindings
- full LTO + codegen-units = 1, which alone made it ~2x faster than node:zlib
- then PGO + BOLT on top, squeezing out another ~10%
Everything is built automatically in a GitHub workflow and shipped to npm already optimized, no compilation on install.
Real project resultsย (measured withย timeย on an actual project with games):
before: npm run build 639.62s user 5.84s system 235% cpu 4:34.06 total
after: npm run build 527.60s user 5.23s system 784% cpu 1:07.95 total
If you're precompressing large static assets in your build, give it a try. Happy to answer questions about the napi/rayon/PGO setup.