AI-generated compiler at scale

Bun ships millions of lines of Claude-generated AOT compiler code, cuts memory 4x AI Engineer
TL;DW
  • Bun's ahead-of-time compiler required five complete rewrites over one month; each rewrite addressed critical performance issues (memory, startup time, compilation speed) that the previous version failed to solve.
  • Testability drives architecture decisions more than implementation approach—pre-existing test suites (Bun's tests, WebKit tests, Test262, Cloudflare's tests) provide confidence in millions of lines of Claude-generated code without writing new tests.
  • TypeScript types treated as predictions, not truths; the AOT compiler can prove value types are monomorphic and become field accesses, otherwise checks runtime type every time with inline caching.
  • Ahead-of-time compilation reduced Cloud Code memory usage 4x, startup time 2x, and beats Go rewrites; Bun's single-threaded compiled version now outperforms TypeScript's hand-ported Go version.
  • Fuzzing with three versions (JIT, AOT, untyped) running side-by-side catches bugs; extending V8 Zilly fuzzer to test TypeScript types improved coverage beyond standard JavaScript fuzzing.
  • During large batches of code generation, run single builds to avoid wasting time on compile errors; switch to long-lived sub-agents after initial code dump so they maintain relevant code context.
  • Prototype pollution vulnerabilities (prototype bans) became security-based breaking changes that also improved performance as side benefit.
  • V8 JetStream 3 benchmarks show Bun AOT outperforms both JavaScript Core's JIT and Node.js V8 JIT in most tests; uglify.js and projects heavy on eval/new Function remain slower with AOT.
  • Models underestimate what they can achieve; explicitly push back with questions like 'can you do this faster?' to prevent self-imposed artificial limits and achieve 10% gains instead of 0.1%.
  • Hourly scorecard updates posting previous vs. current metrics to Slack enabled real-time visibility into project health; essential for tracking direction when managing millions of lines across five rewrites.

Jarred Sumner details how Bun used Claude agents to build its ahead-of-time JavaScript compiler across five major rewrites, achieving 4x memory reduction and 2x faster startup. Testability drove the architecture: running code under JIT, AOT, and untyped modes against existing test suites let agents iterate without writing new tests.