How GitHub Rewrote the Copilot Runtime in Rust — Using Copilot Itself

Stackademic

GitHub migrated roughly 830,000 lines of production TypeScript to Rust, with the AI assistant doing much of the porting work.

GitHub published a detailed account this week of migrating the Copilot runtime from TypeScript to Rust — a multi-month effort that used Copilot itself to automate porting hundreds of thousands of lines of code. The result: a compiled runtime designed for lower latency, reduced memory usage, and lower infrastructure costs.

For developers curious about when AI-assisted refactoring crosses from demo to production, this migration is one of the clearest case studies available.

Why rewrite a working runtime?

The Copilot runtime is the component that receives requests from IDEs, orchestrates model calls, and returns completions. It was originally implemented in TypeScript on Node.js — a reasonable choice for rapid iteration and ecosystem compatibility.

As Copilot scaled, the costs of interpreted execution became harder to ignore. Latency directly affects developer experience: slower completions feel broken even when model quality is unchanged. Memory footprint affects how many concurrent sessions a single node can serve. Infrastructure cost compounds at GitHub's traffic volumes.

Rust offered a path to compiled performance without a garbage collector, strong memory safety guarantees, and growing adoption in systems programming. The tradeoff was migration cost — especially for a codebase measured in hundreds of thousands of lines.

The migration by the numbers

When the project started, production code was entirely TypeScript. By completion:

  • Production Rust grew to approximately 830,000 lines
  • TypeScript production code fell to zero
  • Rust unit tests added another 469,000 lines

Those numbers illustrate both the scope of the rewrite and GitHub's emphasis on test coverage during the transition. A runtime that powers one of the most widely used AI coding tools cannot afford regressions.

Using Copilot to port Copilot

The meta aspect is what makes this story compelling. GitHub's team used Copilot to generate Rust equivalents of TypeScript modules, then reviewed, tested, and integrated the output. Over time, the tool that engineers were migrating became the primary tool doing the migration.

This is not "AI wrote our codebase without human oversight." It is AI accelerating a mechanical translation layer — pattern matching, boilerplate generation, and API surface replication — while engineers retained responsibility for architecture, correctness, and performance validation.

Practical lessons for teams considering similar moves:

  1. Start with clear module boundaries — Rust migration works best when TypeScript modules have well-defined interfaces.
  2. Invest heavily in tests before porting — The 469,000 lines of Rust tests are not overhead; they are the safety net that makes AI-generated ports shippable.
  3. Use AI for translation, not design — Copilot excelled at syntactic and structural conversion. Architectural decisions remained human.

Performance outcomes

GitHub reports tangible improvements: lower latency for user requests and reduced infrastructure costs. Exact benchmarks were not the focus of the public write-up, but the engineering motivation is straightforward — a faster runtime serves more developers per dollar of compute.

For Rust skeptics, the migration is evidence that Rust is moving from "systems language for browsers and databases" to "default choice for performance-critical services" — including AI infrastructure.

What this means for your stack

Most teams will not rewrite 830,000 lines this quarter. But the pattern is transferable:

  • Identify hot paths where latency or memory dominates cost
  • Prototype Rust (or another compiled language) replacements for those paths only
  • Use AI coding assistants to reduce porting friction, not to skip review

GitHub's migration also normalizes a workflow that would have seemed absurd three years ago: using an AI pair programmer to rewrite the AI pair programmer's own backend.

Whether that recursion continues — Copilot improving itself in tighter feedback loops — is an open question. For now, the Rust runtime stands as proof that large-scale, AI-assisted language migration is production-viable when tests and human review keep pace with generation speed.

Comments

Loading comments…