Build Tool Truths: Benchmarks from a Handwritten Mini Bundler
Build tooling decisions directly affect iteration and deployment speed; this experiment gives hard numbers on the trade-offs between chunk granularity, hash chaining, and tree-shaking correctness, which any team tuning its bundler can use to decide where to invest.
The article walks through building a complete mini bundler from scratch, with 33 assertions and 5 differential tests against native ESM. Its results challenge common beliefs: regex-based scanning is 43.7x faster but misidentifies imports in comments/strings 3/3 times; tree-shaking mostly reduces output by excluding unreachable modules, not clever elimination; per-module chunking cuts invalidation to 0.4% but multiplies requests; chaining dependency hashes boosts blast radius 214x. It also measures performance hot spots and shows that optimizing code with charCode comparisons and single-pass linking yields multi-fold gains, and that hand-written BigInt hashing is far slower than native sha256. The article ends with practical advice on when to write your own bundler and how to diagnose slow builds by stage.
The most striking claim is that tree-shaking's biggest gains come from excluding modules from the graph rather than from clever liveness analysis; this implies optimizing entry-point fan-in is more effective than tuning a shake algorithm.
The 214x blast-radius amplification demonstrates that chunk granularity and hash chaining are two independent knobs for cache behavior; teams that conflate them risk either constant stale caches or deploy-time 404s.
The 'green build but wrong output' bugs highlight a deeper truth: correctness in a bundler cannot be proven by unit tests alone; differential testing against native ESM is the only reliable safety net, and it only works if your fixtures actually exercise the semantics that matter.
The performance measurement section warns that aligning baselines to reachable modules is as important as measuring; without it, you can get absurd conclusions like 'graph building is faster than lexing', which would lead to misdirected optimization decisions.