YouTube Summaries

← All summaries

AI made Rust rewrites cheap enough to do

2026-08-10 Mon ⏱ 25 min forrestknight

Rust is over ten years old and nothing fundamental changed in the language this year, yet Microsoft, Meta, Cloudflare, OpenAI and others all moved major code bases to it within twelve months. The argument is that the trigger is economic, not linguistic: AI-driven porting collapsed the cost of a rewrite from years of engineer-time to days of token spend, so ports that were always attractive but never justifiable finally cleared the bar. The second half of the argument is that Rust is genuinely the right target for many of these use cases, and that its strict compiler is what makes it an unusually good fit for autonomous AI loops. The closing caveat is that Rust remains a real trade-off, not a magic bullet.

Bun: Zig to Rust as the template case

Bun, one of the most prominent Zig code bases ever written, was ported to Rust after Jarred (Bun's founder) ran an AI porting experiment in May. The experiment was merged into main. The raw port, before any cleanup, passed Bun's entire test suite, fixed a batch of memory leaks and flaky tests, and came out smaller and faster.

The underlying reason Bun had those bugs is a memory-model mismatch: Bun sits on top of JavaScriptCore, which is garbage collected, while Zig memory is manually managed. The bug list in the blog post is dominated by heap-use-after-free crashes, memory leaks and race conditions. Jarred had earlier determined that a large share of these bugs would have been compiler errors in Rust rather than production incidents. This is framed as a use-case fit issue, not "Zig bad, Rust good".

Before AI made the port feasible, the calculus was blocking: 535,000 lines of Zig, and a hand port would have meant pulling a full team off feature and bug work for at least a year. The fallback plan was to add Rust-inspired homegrown smart pointers to the Zig code — worse ergonomics than Rust and none of the guarantees.

The economics of the actual port:

  • Cost about $165,000 at API pricing, over roughly 11 days, driven by essentially one person.
  • Jarred's own estimate for a hand port: three engineers with full context, about a year. Average Bun engineer salary is cited at about $160,000, so three engineer-years is comparable to the token bill.
  • Comparison points suggest that estimate was optimistic: Dropbox's sync engine rewrite took about four years and six engineers (though it was a full architectural redesign, not a one-to-one port), and the TypeScript port to Go took roughly five to eight engineers about two years.

The port was not a single prompt but a structured process resembling how a team would approach it, using an at-the-time unreleased model (Fable 5) that iterates and loops through a project.

Meta: Flow, and a broader internal Rust push

Meta ported Flow, its OCaml type checker (the one React is written with), to Rust. The interesting part is the choice: Rust was the harder port. OCaml is garbage collected, so Go or Kotlin would have been the natural targets — all three use mark-and-sweep GC — and both were genuine candidates in Meta's original analysis. This mirrors the TypeScript-to-Go decision, where ease of porting was an explicit reason for picking Go.

Meta chose the riskier Rust port to sit inside the ecosystem JavaScript tooling is converging on — SWC, Rolldown, Biome, Vite — for the integration opportunities. The idea dates to 2019 and was shelved purely on cost; in 2026 the cost dropped and they executed. Result: roughly 2x general performance improvement and up to 100% faster execution on heavy workloads.

The process was not human-out-of-the-loop. The first full Rust version passed zero tests. Later it was still slower than OCaml until humans went in and fixed allocation patterns. AI did the grunt work and expedited the process; humans refined.

Other Meta Rust adoption: the React compiler was ported from TypeScript to Rust (again starting as an experiment that got merged), and decades-old C in a core messaging library touching Messenger, Facebook and Instagram messages is being rewritten in Rust.

Aside: the first Rust compiler was itself written in OCaml, so Rust replacing OCaml in code bases like Flow is a student-becomes-master situation.

Getting Rust's benefits without writing Rust

Sometimes the win comes from dependencies rather than a rewrite. Vite 8 swapped its bundler for Rolldown, which is written in Rust, and:

  • Linear's production builds went from 46 seconds to 6 seconds.
  • Ramp cut build times by 57%.
  • Mercedes-Benz cut theirs by up to 38%.
  • Beehiiv cut theirs by 64%.

None of these companies did anything beyond a routine dependency upgrade. The takeaway is to choose dependencies wisely.

Updates on older Rust adoption stories

  • Linux kernel: at the December kernel maintainers summit the Rust experiment was declared concluded — and Rust is officially staying. This follows last year's drama with a maintainer calling Rust a cancer to the kernel and resignations over it. More recently at Rust Week, Greg Kroah-Hartman, who runs the kernel CVE team, presented a new Rust type called untrusted that he claims could eliminate 80% of the CVEs the kernel generates.
  • Microsoft: after last year's Rust font rendering work, Rust is now running in the Windows kernel.
  • Cloudflare: their core proxy, an Nginx-based system fronting a large share of the web for over a decade, was replaced with a Rust system called FL2; sites got 10 ms faster at the median.

AI labs converging on Rust

This matters recursively: if AI labs write in a language, they are likely to prioritize it in training, making models better at it — which appears to already have happened with Rust.

  • OpenAI rewrote the Codex CLI from TypeScript to Rust, and acquired Astral (makers of uv and Ruff — Python tooling built in Rust), whose Rust engineers moved into the Codex org, suggesting a partial acquihire motive.
  • SpaceX AI open-sourced its Grok Build CLI, written in Rust — not a rewrite, but Rust from the start. Noted separately as a genuine problem: the CLI at one point silently packaged the user's entire repo and uploaded it to their own cloud bucket; this was backtracked and the uploaded code supposedly deleted.
  • xAI replaced the Scala/Java recommendation algorithm on X: the orchestration layer, post store and serving pipeline are all Rust, tying together the Grok-based ranking model called Phoenix.

The two reasons, and why Rust suits AI specifically

First, rewrites are viable now, and the sole factor is AI. Porting a whole code base almost never penciled out — too complex, too expensive, too slow, payoff too uncertain. Now one or two engineers driving AI can do the bulk of the work at a fraction of cost and time, which also makes speculative experiments worth running.

Second, Rust is genuinely a good language for these use cases — chosen even where it was the harder, less convenient option.

The two reinforce each other. When Bun's port hit roughly 16,000 compiler errors, 64 Claude agents looped on cargo check overnight, fixing them file by file, fully autonomous. The Rust compiler replaced the human reviewer in the feedback loop; because it catches more classes of mistake than other compilers, it is an unusually good verifier for agentic coding.

A longevity caution is raised by analogy: companies that laid people off in early 2025 citing AI are now hiring back for those same roles, so short-term-looking wins deserve scrutiny over time.

The caveat: Rust is not a magic bullet

Mitchell Hashimoto evaluated Rust for Ghostty and chose Zig. His reasons are partly aesthetic — he does not enjoy reading and writing Rust, calling it a stylistic choice — and partly technical:

  • C interoperability. Zig does this exceptionally well; Hashimoto was looking for a better C and Zig felt like it. In Rust, every bit of C and C++ contact is FFI with unsafe blocks and binding code — handled, but not optimal if C interop is central. Bun's code base carries about 4,000 permanent unsafe blocks as a consequence.
  • Memory management preference. He wants explicit, intentional allocation decisions without negotiating with the borrow checker.

Others avoid Rust simply because they do not want to wait on the compiler, and pick Go instead.

Open question: who funds the plumbing rewrites

Many Rust rewrites are of unowned, unmonetized infrastructure — sudo, coreutils, and much of the internet's plumbing that nearly everyone depends on. Funding comes partly from big tech and partly from government involvement effectively pushing these rewrites, though not a hard mandate in the style of Ada. Why that is happening is flagged as a topic for a future video.

Takeaway

Rust did not change this year; the cost of switching to Rust did. That reframes both rewrite decisions for existing code and the default language choice for new projects — but the case-by-case fit still decides, and Zig, Go or staying put remain right answers depending on memory model, C interop needs and team preference.