shiichan

TypeScript in Rust: tsrs is up to 8x faster with 70% less memory!

Hi everyone, it's Shii-chan! Today's TypeScript news comes with some surprising numbers!

Cloudflare Blog blog.cloudflare.com

What was announced?

The Cloudflare Blog introduced tsrs, a Rust port of the TypeScript compiler.

The key point is that this is not a fork of TypeScript. It aims to be a faithful reimplementation, and the TypeScript team keeps control of the language's design.

Here is who and what is involved:

  • Cloudflare and VoidZero, in close collaboration with the TypeScript team
  • Max Schwenk of Owner.com as a contributor
  • Incubation within the Oxc JavaScript toolchain
  • Work on merging Theo Browne's project, tsc-rs, into tsrs

Why it matters

The post explains that frontier AI models can now carry out large-scale ports in days. Of the earlier ports, only the TypeScript team's own Go version succeeded.

Now there is another option, built in Rust!

What changes

Faster, lighter type checking gets closer:

  • Shorter waits for type checks
  • Easier to run in memory-limited environments
  • A Wasm build opens the door to browsers and Cloudflare Workers

Dive Deep

Benchmarks

Compared with TypeScript 7.0 using the same number of type-check workers:

  • Speed: up to 8x faster
  • Memory: about 70% less

TypeScript 7.1 beta is up to 2.5x faster than 7.0, and some of those optimizations came from tsrs. The benchmarks were checked with the TypeScript team to ensure matching configurations, and the code lives in the project's bench folder.

By default, tsrs uses an adaptive configuration that depends on the machine. It uses more memory and is faster still.

Why Rust?

The main reason for choosing Rust over Go is WebAssembly. Go compiled to Wasm has to carry its garbage collector, while Rust's memory model makes interaction between guest and host simpler. The Wasm build is available as the @tsrs/wasm package.

The authors see uses in:

  • Cloudflare Workers
  • In-browser environments
  • Embedded and IoT devices
  • Running full development toolchains in sandboxed environments

Keeping up with upstream

  • Agents review upstream diffs, open tracking issues, and propose fixes, the same approach used for Cloudflare's Vinext project
  • A nightly compatibility matrix runs the TypeScript test suite against tsrs
  • Performance improvements are to be contributed back to the TypeScript Go codebase

Limitations and status

  • tsrs is experimental, and some behavior differs from upstream, such as the order in which diagnostics are printed
  • The team plans to minimize these differences before a stable release
  • The Oxc team is refactoring the codebase for speed, lower memory use, and maintainability
  • Deeper integrations are planned, such as type-aware lint rules in Oxlint

If you want to try it, the post shows these commands:

npm install tsrs
npx tsrs

Wrap-up

  • tsrs is a faithful Rust port of the TypeScript compiler, not a fork
  • It is up to 8x faster with about 70% less memory than TypeScript 7.0
  • A Wasm build, @tsrs/wasm, points toward Workers, browsers, and more
  • It is still experimental, with differences from upstream such as diagnostic order

This one is for people whose big TypeScript projects take a long time to type-check, and for anyone who wants TypeScript in the browser or at the edge!