newsfilter
← Interviews
AI Engineer22 min

How to Ship Millions of Lines of Agent-Written Code — Jarred Sumner, Anthropic

Jarred Sumner, Jared

Conference Presentation
  • Jared, creator of Bun at Anthropic, recently merged a several-million-line PR adding an ahead-of-time (AOT) compiler to the Bun JavaScript runtime.
  • The project involved rewriting the compiler five times over the summer to balance code quality, compilation speed, and functional correctness.
  • Cloud Code, the application powering the runtime, uses approximately 4x less memory and starts 2x faster with the new AOT implementation compared to the previous JIT version.
  • In the JetStream benchmark, Bun (compiled AOT) outperforms both JavaScript Core's JIT and Node.js (V8's JIT), though the JIT remains faster for code-heavy in eval or new Function scenarios like Uglify.js.
  • The decision to implement an AOT compiler rather than rewriting Cloud Code in Rust was driven by the ability to run the existing TypeScript test suite against both runtimes without porting the test suite itself.
  • Rewriting Cloud Code in Rust was rejected due to the high risk of invalidating the test suite if the tests themselves required porting, making confidence in the rewrite impossible.
  • The compiler treats TypeScript types as predictions rather than guarantees, a strategy that allows large language models to generate compiler logic effectively.
  • Verification relies on running three variations of an application (standard, AOT, and non-typed) to ensure behavioral equivalence, supplemented by fuzzing using an extended version of the JavaScript engine fuzzer.
  • A major architectural improvement was shifting from a single long-running agent to using long-lived subagents with persistent context to manage the 900,000-line codebase.
  • The compilation time for the entire Cloud Codebase was reduced from 50 seconds to under 20 seconds, addressing developer expectations for near-instant compilation.
  • Two breaking changes were introduced in the AOT compiler: one preventing prototype pollution attacks and another improving performance, both of which are security-critical.
  • The project utilized a batched development strategy where agents wrote code in large volumes simultaneously, followed by a phase dedicated to fixing build errors and validating against a massive test suite including WebKit, Test262, and Cloud Code tests.
  • Continuous monitoring was maintained via hourly Slack scorecards comparing metrics between build versions to track performance regressions or improvements in real-time.
  • The team leveraged the AOT compiler to build the compiler itself (self-hosting), creating a bootstrapping loop where the compiler was used to compile Cloud Code, which was then used to compile Bun.
  • Jared notes that without active nudge prompts like "do this faster" or "why is this taking so long," LLMs tend to settle for 0.1% improvements rather than the ambitious 10%+ gains targeted in this project.
  • The AOT compiler is currently being dogfooded internally and is scheduled for external release soon, with a beta version available via bun-upgrade-canary and bun-compile.
  • Future plans include adding multi-threading support to the AOT compiled version of Bun, though this feature is not yet implemented.
  • TypeScript 7 reportedly achieved faster performance in single-threaded scenarios when compiled via bun compile compared to their own hand-rewritten Go port, highlighting the potential of the new compiler.