Tsrs: A Port of TypeScript to Rust
Introducing tsrs: A Rust-Based Port of TypeScript
Cloudflare and VoidZero, in partnership with Max Schwenk from Owner.com, are excited to announce tsrs—a comprehensive port of the TypeScript compiler written in Rust.
This project is being developed in tight coordination with the official TypeScript team and is currently being incubated as a component of the Oxc JavaScript toolchain.
The Core Mission
Our primary objective is to minimize the time developers spend waiting for type-checking to complete, allowing them to focus on actual creation. By enhancing memory efficiency and execution speed, we can bring full-scale development environments to new frontiers, including directly inside the web browser.
Our Philosophy on Governance: We believe the TypeScript team must retain absolute authority over the language's evolution and design. Their long-term stewardship has been vital to TypeScript's widespread adoption. Because the official team often spends years prototyping and refining features,
tsrsmust mirror those decisions exactly to avoiddivergenceincompatibility.
Performance and Memory Metrics
Initial benchmarks indicate that tsrs offers significant improvements over TypeScript 7.0. When utilizing an identical number of type-check workers, the results are as follows:
| Metric | TypeScript 7.0 | tsrs (Rust Port) | Improvement |
|---|---|---|---|
| Execution Speed | Baseline | Faster | Significant |
| Memory Usage | Baseline | of Original | Reduction |
Note: TypeScript 7.1 beta already shows internal gains, performing up to faster than version 7.0. Some of these improvements were actually derived from tsrs optimizations that were upstreamed.
To ensure accuracy, we collaborated with the TypeScript team to standardize configurations, avoiding the common pitfall of comparing different machine types or default settings. While tsrs offers a standard mode, it also includes an adaptive configuration that leverages more memory for even greater speed depending on your hardware.
Give it a Try
tsrs aims to be a mirror image of the original compiler. You can test the experimental build via npm:
# Install the package
npm install tsrs
# Execute the compiler
npx tsrs
Why Transition to Rust Now?
Historically, porting TypeScript has been a monumental task. In fact, only one major effort succeeded: the official team's transition from JavaScript to Go. However, the landscape has changed because:
- AI Acceleration: Modern frontier AI models can now handle massive porting tasks almost autonomously in a few days.
- Diverse Implementations: We are now seeing a surge of "slopforks," faithful ports, and total architectural rewrites in C++ and Rust.
The Wasm Advantage: Rust vs. Go
You might wonder why a Rust port is necessary if the Go port already provided a speed boost. The answer lies in WebAssembly (Wasm).
- Go: Requires compiling the garbage collector (GC) into the Wasm binary.
- Rust: Its memory model allows for direct, efficient interaction between the Wasm guest and the host.
This makes Rust the superior choice for memory-constrained environments. With Cloudflare's recent support for native Rust in Workers (via the wasm-bindgen Emscripten target), we can now run entire build systems in tight loops.
This efficiency enables sandboxed, end-to-end development toolchains on Cloudflare, which can be deployed to:
- Client-side browsers
- Embedded devices
- IoT applications
The Path Forward
Our strategy for maintaining parity and expanding functionality involves a two-pronged approach:
1. Feature Integration
We are collaborating with Theo Browne to merge tsrs and tsc-rs into a unified package. This will ensure support for:
- The Language Server Protocol (LSP)
- Content mappers
- Full TypeScript feature parity
2. The Sync Engine
To prevent the port from drifting, we are implementing an automated synchronization pipeline similar to how we manage Vinext relative to Next.js.
The Daily Workflow:
- Morning: Agents analyze upstream changes and flag potential impacts.
- Night: The compatibility matrix is updated by running the official TypeScript test suite against
tsrs. - Resolution: Agents identify the delta, build a reproduction case, and propose the necessary code port.
Final Goals
- Eliminate discrepancies in diagnostic print ordering.
- Reach a stable release with minimal divergence from upstream.
- Upstream performance wins back to the TypeScript Go codebase.
Cloudflare continues to champion the Rust ecosystem with tools like Vite, Rolldown, Oxlint, and Oxfmt. For our 10 million+ developers, tsrs represents the next step in making the JavaScript toolchain faster, more portable, and more accessible.