How React Compiler’s Rust Port Boosts Build Speed Up to 10× with AI‑Assisted Code Migration

The React team fully migrated the React Compiler from TypeScript to Rust, combining human‑designed architecture with AI‑generated code, achieving up to 10× faster core conversion, a 3× overall compile speed increase, seamless integration with Babel, SWC and OXC, and a rigorous three‑layer testing regime.

21CTO
21CTO
21CTO
How React Compiler’s Rust Port Boosts Build Speed Up to 10× with AI‑Assisted Code Migration

Recently the React core team merged a high‑visibility PR that replaces the TypeScript‑based React Compiler with a Rust implementation. The migration, led by core member josephsavona , showcases a novel workflow where humans define the architecture and AI assists in bulk code generation, while developers perform extensive review and quality checks.

Why Move the Compiler to Rust?

The original compiler, built in TypeScript, offers strong readability and ecosystem compatibility but suffers from JavaScript’s runtime performance limits and garbage‑collection overhead in large‑scale projects. Rust’s zero‑cost abstractions, memory safety, and lack of GC directly address these bottlenecks.

Significantly reduce compilation time and accelerate large front‑end builds.

Break free from JavaScript runtime constraints and integrate with next‑generation Rust toolchains such as SWC and OXC.

Establish a high‑performance shared library for future deep integrations.

Human‑Designed Architecture + AI‑Driven Bulk Coding

The top‑level design, layered architecture, incremental migration plan, and comprehensive test strategy were all manually defined. AI was then tasked with type conversion, logic replication, line‑by‑line translation, and repetitive template generation. Developers rigorously audited the AI output, aligning logic, fixing bugs, and refactoring until the Rust code reached production‑grade quality.

Unified Middle‑Layer Design for Multi‑Tool Compatibility

The new Rust compiler adopts a unified interface: it accepts a Rust Babel AST as input and emits a Babel AST as output, using Babel AST as the cross‑tool exchange format. This allows tools like Babel, OXC, and SWC to integrate with a single conversion layer. Future plans include embedding binding and reference calculations to eliminate external scope data injection.

Internally, the Rust version mirrors the original TypeScript architecture: the outer AST is transformed into a custom high‑level intermediate representation (HIR), then optimized through multiple passes using a control‑flow graph (CFG) and static single‑assignment (SSA) form. The primary divergence lies in the data storage model—Rust’s ownership model necessitates an arena‑based memory pool with index references, reducing allocation overhead.

Performance Highlights

In Babel plugin mode, the Rust version is roughly 3× faster than the TypeScript baseline.

After stripping serialization and format‑conversion costs, the core conversion logic runs up to 10× faster.

Direct native integration with SWC or OXC could further amplify performance by removing AST round‑trips.

Comprehensive Three‑Layer Testing

To guarantee correctness, the team built three automated test suites: yarn snap --rust: compares Rust and TypeScript compiler snapshots to ensure identical output. test‑e2e.sh: end‑to‑end validation of Babel wrapper, OXC native, and SWC native integration modes. test‑rust‑port.sh: deep internal checks that compare the intermediate state after each compilation pass, preventing migration drift.

All 1725 test cases passed snapshot comparison, and the Rust compiler’s error messages, generated code, and HIR structures match the TypeScript version with only minor ID normalization differences. Sample integrations with OXC and SWC run successfully, confirming compatibility.

Future Ecosystem Collaboration

The React team is opening collaboration with major Rust compiler projects (SWC, OXC). Planned integration steps include:

SWC and OXC handle lightweight adaptation and lint pipeline connections.

Encapsulating the core logic into independent crates react_compiler_swc and react_compiler_oxc hosted in the official React repository.

Centralizing algorithm updates, bug fixes, and feature upgrades in the official repo, reducing downstream maintenance effort.

Pending Optimizations

Refine function return types from Option<program> to an incremental patch‑style structure for better incremental compilation support.

Fine‑tune the AST using smol_str to shrink string overhead and memory usage.

Implement built‑in scope analysis to eliminate reliance on external serialized scope data, achieving a fully closed‑loop compilation pipeline.

Conclusion

The large‑scale migration of the React Compiler from TypeScript to Rust is more than a language rewrite; it marks a milestone in front‑end compilation. By leveraging Rust’s performance advantages and validating a “human‑designed architecture + AI‑assisted coding” workflow, the project demonstrates a viable path for refactoring massive open‑source codebases. As subsequent versions stabilize, React’s build speed and runtime optimization capabilities are expected to see a noticeable uplift.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PerformanceCompilerReactRustBabelSWCAI-assisted migration
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.