Tsrs: A Port of TypeScript to Rust
164 points by hnisjafx40 5 hours ago | 86 comments

DanRosenwasser 2 hours ago
Hey there, TypeScript team member here. The tsrs project has been extremely interesting to see come together. We've been working with the maintainers to better understand how tsrs is fast and what sorts of optimizations it uses are safe. We even did our own Rust vibe port and what we currently suspect is that a lot of the speed does not just come down to language choice, and some of what is going to make TS 7.1 faster and leaner (see the charts in the blog post) actually comes from optimizations discovered in tsrs.

We think the wasm and oxlint integration makes a lot of sense for Cloudflare's needs, so this investment makes sense. At the same time, we'll be working hard and collaborating to make the official TypeScript toolset faster and even more efficient.

Congrats to the tsrs team on making this official. We're excited and we look forward to continuing on collaboration!

reply
samuelstros 2 hours ago
At this point, why invest further in TSGO?

No matter how many optimizations can be ported from tsrs to ts-go, Rust will be more efficient and enable the WASM use case.

The premise of porting the compiler from TS to GO was ease of migration due to Go's garbage collector. That doesn't hold anymore? AI doesn't care how hard or easy a migration is if a test suite exists.

reply
fallingbananna 3 minutes ago
Because TSGO is stable and compatible?

I assume that most of the speedup in ts-rs does not simply stem from using a language without garbage collection, but actually from doing smart optimizations that can be done in any langauge.

Similar to how uv in the Python world explained that their implementation being in Rust has very little to do with the most impactful speedups they did.

reply
platinumrad 2 minutes ago
I just vibecofed tsasm. tsrs is obsolete now and anyone who still uses it is hopelessly behind the times. The tsrs team should delete the repository immediately and join my project.
reply
magicalist 2 hours ago
> That doesn't hold anymore? AI doesn't care how hard or easy a migration is if a test suite exists.

Sure, but that only matters if migration is going to be the last thing anyone does on a project. Unless you think typescript 7.1 ought to be enough for anybody, it also matters what the typescript team wants to write/read/reason in.

reply
wavemode 2 hours ago
Your answer is within the comment you wrote. AI is maintaining tsrs whereas humans are maintaining tsgo.

Your question boils down to "why would humans maintain something?" which could have a variety of answers depending on context.

reply
greenavocado 40 minutes ago
No, the question is now: "How much human mental momentum, ego, and investment is there in and behind any particular project or its forks?"
reply
pier25 35 minutes ago
TSGO is already plenty fast and overkill for most projects.

Sure the Rust version is faster but the difference is probably only noticeable in the top 1% largest projects.

reply
theappsecguy 28 minutes ago
Fast is one thing, TSGO is fast enough I think, but my god does it suck up memory
reply
alain_gilbert 29 minutes ago
I'm always mind-blown when I read stuff like "speed is overkill". Speechless!
reply
pier25 23 minutes ago
do you go to the supermarket with an F1 car?
reply
alain_gilbert 16 minutes ago
Do you usually dig up your garden by hand with a shovel, or do you use a rototiller?
reply
pier25 5 minutes ago
Now we're getting somewhere. This is a great example because obviously speed depends on the context.

Obviously a shovel is quite an improvement for home gardeners but big constructions need a completely different tool.

For +99% of TS projects going from eg 10ms to 1ms is not going to make any difference even though it's a 10x improvement. In part because most monitors refresh at 60hz (16ms per frame) but even with +120hz monitors this is not going to have an impact on any workflow. Even for CI network latency is going to be a much bigger factor than improving TS compilation beyond the performance that TSGO already provides.

reply
seanw444 8 minutes ago
Do you dig your garden with an excavator?
reply
egonschiele 2 hours ago
Thanks for the response and it is encouraging to hear that there's more to this project than vibe coding! Sounds like some interesting things were found in the process, and I'm all for vibe coding as a way to learn new things.
reply
zyf 2 hours ago
Been with TS for many years now and the work your team's done over the years is amazing. Thank you
reply
satvikpendem 39 minutes ago
Ah I was gonna ask what happened with tsc-rs by Theo but looks like you guys are merging it in, at least it won't be a waste of his $500k in token spend, lol.
reply
lemagedurage 2 hours ago
Thanks for the input, glad to hear both parties benefit.

Could you elaborate on what type of optimizations were added to TS 7.1? As in, were they more algorithmic or related to memory management?

reply
DanRosenwasser 59 minutes ago
If I recall correctly, a few of both - there were instances where some work could be done more lazily/minimally (https://github.com/microsoft/TypeScript/pull/64476), and there were instances where we changed our allocation patterns and played around with some struct layouts. We originally strived not to drastically reorganize our data structures to make things easier to port, and we have more flexibility now. We're continuing to experiment more here.
reply
afdbcreid 2 hours ago
It appears they're using a unique memory model (https://github.com/oxc-project/tsrs/blob/main/docs/PORTING.m...) to overcome the challenge that prevented the TypeScript team from choosing Rust to begin with: Rust has no GC and porting from a GC language to it often requires restructure of data.

Essentially, they fake a GC via never-freed arenas for long-living objects. It's interesting that Rust can do that (hopefully soundly)!

reply
zamalek 2 hours ago
From the file:

>Create with P::new(value). p.get() returns &'static T. [...] unless an explicit recycling site proves them dead

It's unsound, the LLM/human is doing the proving. They've hidden unsafe in an abstraction without removing the unsafeness. Using the arena allocator's lifetime would have been safe and easy (bumpalo recommends this AFAIK).

I'm guessing a sycophantic LLM either found or praised this load-bearing seam.

Never deallocating would have been sound (missile memory management: https://devblogs.microsoft.com/oldnewthing/20180228-00/?p=98... ).

reply
afdbcreid 2 hours ago
With sanitizers (https://github.com/oxc-project/tsrs/blob/main/notes/mem-recy...). We're back to C I guess. I hate this project now.
reply
lioeters 35 minutes ago
> load-bearing seam

Zing!

reply
jcmontx 2 hours ago
Wouldn't that eat the whole ram?
reply
sheepscreek 3 hours ago
Ah took me a while to understand the reason behind this.

It wasn’t “let’s build a faster Rust based Typescript compiler” at all. That was a nice side-effect.

They needed a Typescript compiler that can run on their WASM only sandbox. So the only existing option was to export tsc Go to WASM, but that comes with the full Go runtime.

And to avoid that cost, they experimented with a Rust compiler and turns out it’s even faster than the reference tsc/Go implementation.

reply
nitsky 2 hours ago
Another reason: type aware listing in oxlint.
reply
anamexis 2 hours ago
Oxlint already has type-aware linting, integrated with TS7/typescript-go.
reply
egonschiele 3 hours ago
It's exciting to see the speed gains. I use TypeScript every day on a large codebase, and it is too slow to run locally. I don't love this change though:

> However, frontier AI models can now do large-scale ports almost independently in a matter of days

> I wrote zero code. Not "barely any". Zero

So we are going to move from a carefully handwritten port to an entirely AI-generated port. I know this is the way the industry is headed, I use coding agents a ton. But I still review their output because they often don't make sound architectural decisions. Maybe this is a sign that my way of working is going away. I'm not sure how to justify that kind of time spent when someone can do the same thing in a matter of days with barely any effort.

I am working on my own language now, I've spent most of this year on it. The idea that someone could just replace it in a matter of days is wild. Wonder how the TS team at Microsoft feels about this.

reply
TheSamFischer 3 hours ago
> The idea that someone could just replace it in a matter of days is wild.

They didn’t design a language that millions of human engineers enjoy (?, lol) using. They took an existing codebase and ported it. Yes, the porting part is easier now but only because another project and spec exist.

reply
FuckButtons 3 hours ago
While this is true - and I see the same sentiment as i am about to make ad nauseam - it is kind of amazing how far the goal posts have moved in such a short space of time.
reply
TheSamFischer 2 hours ago
It’s not a goal post. It was literally a fucking benchmark of the very first LLMs.
reply
egonschiele 3 hours ago
That's fair, I was thinking the same – porting must be simpler, especially if there's already a substantial test suite
reply
onlyrealcuzzo 3 hours ago
If TypeScript has the integration testing framework in place to verify that the compiler actually works (and it should) - then, presumably, you should be able to swap in a Chinese Room black-box and - at least - know that it works.

You do have to be worried that it's possibly installing trojan horses on your computer while compiling code, or any other number of unwanted side effects.

But you can and should be able to have integration testing in place to know that a compiler - at a minimum - actually works.

reply
egonschiele 3 hours ago
Totally fair. The thing is, though, agents often write code in ways I don't expect, and I don't think any human would write, which makes me think that code may also break in a way that no human expects or would have written a test for.
reply
spiderice 27 minutes ago
Your way of working is definitely going away. And quickly. The idea of reviewing code today is already a questionable use of time. In a few more months to a year it will clearly be a waste of time.
reply
panzi 4 minutes ago
I wonder how fast "Doom in TypeScript" runs in tsrs now. XD
reply
gzapp 2 hours ago
Shameless plug of my Typescript C# port. It's a case study with some interesting (perhaps) notes from me in the README about approach, performance, and cost(~$75).

https://github.com/stepwisehq/typescript-dotnet

reply
Leynos 4 hours ago
So that's three now. This, tsgo-rs, and `bun check`
reply
alexanderson 3 hours ago
They mention in the post they are working with Theo to absorb tsgo-rs into tsrs.
reply
Leynos 3 hours ago
Nice. I missed that. This is good news.
reply
Rapzid 2 hours ago
Why would they bother merging his vibe slop if theirs is better?
reply
shimman 2 hours ago
Big tech looks out after their own. That's all there is to it.
reply
Rapzid 2 hours ago
Prob a PR thing with a quick merge to /dev/null
reply
AbuAssar 4 hours ago
According to voidzero, this port is up to 8x faster than TS 7.0 & ~70% less memory.

Microsoft should seriously consider porting typescript to rust at this point

reply
aleksandrm 3 hours ago
I'm pretty sure they already considered it before settling on Go. Allegedly, they chose Go because it was easier to translate to.
reply
satvikpendem 41 minutes ago
That was pre-AI. Ironically if they waited just another year they could've done this port directly to Rust themselves.
reply
ndr 4 hours ago
I wonder how more frustrating is it to work on the compiler in rust vs go.

IIRC at the time of the port to go they wanted fast test and compile time, of course it's a different era now.

reply
lemagedurage 2 hours ago
That's interesting. A go version to iterate on the code and a rust version to run the code might be an optimal split here.
reply
tgv 3 hours ago
Idk. Apart from the fact that benchmarks are generally of questionable value, what's the point? Is the TS compiler unbearably slow?
reply
pier25 33 minutes ago
> Is the TS compiler unbearably slow?

It's not. Even the JS compiler is still fast enough for many projects given the single core improvements in hardware (eg Apple Silicon).

reply
ruther4d 3 hours ago
They say the point in the article - WASM
reply
msdz 3 hours ago
(Not sure if this could be a genuine remark or is more of a joke, but)

Why not vibecode a Go -> WASM cross-compiler, then?

reply
AbuAssar 3 hours ago
Go needs a garbage collector while rust doesn’t.
reply
Lvl999Noob 3 hours ago
Wasm comes with a garbage collector though, no? So a garbage collected language that offloads all memory management to the runtime would actually be better than one that ignored the platform and does its own stuff.
reply
zamalek 3 hours ago
Apparently there were some design issues (raised and ignored) that made it unusable for many languages.
reply
Tadpole9181 3 hours ago
The JVM alone has, what, 4 different modern GCs now? Garbage collectors aren't really universal, so they can pose different issues for different languages.
reply
msdz 3 hours ago
Yes, of course, but couldn’t you have/make one in WASM too? (I have no clue how memory is allocated there)
reply
jerf 3 hours ago
Yes, and when you ship a Go WASM package it is already included. But it has a certain impedence mismatch with WASM since it is rolling its own stuff that WASM can't see, I believe the performance is a bit less good than it could be, and it results in very large WASM packages for small amounts of code.

Since a typescript compiler isn't "a small amount of code", you'd have to see specific numbers on the final WASM assembly size to know how relevant that is. I'd expect well-written Rust code to beat well-written Go code on final assembly size by some amount, which may or may not be relevant to any particular use case (since in a lot of cases one "couple dozen megabytes" is much the same as another when it really gets down to it, it's not like Go is going to be emitting gigabytes to Rust's hundreds of kilobytes or something). However I can't judge what AI-written Rust code versus well-written Go code would come out as. AI is not terribly good at being concise (he said, while writing this post between prompts fighting with an AI to make a PR much more concise than it currently is).

reply
ZiiS 3 hours ago
You already can run the Go tsc in WASM using mature tools; but it further amplifies the memory and performance difference between the Rust version (which maps more cleanly onto WASM's design).
reply
Tadpole9181 3 hours ago
1. Porting typescript is made easier by the enormous test suite they can copy for verification.

2. They're doing this for workers, so with a systems-level language, there's a much higher potential for CPU and memory savings (an order of magnitude on this first pass, apparently). Driving their compute costs down is very revenue-efficient at this scale.

reply
tgv 2 hours ago
For workers, you only need to strip the types. There's no need to do the expensive checking.
reply
Tadpole9181 2 hours ago
Did you read TFA?

> Just a few weeks ago we announced supporting native Rust in Workers with the new Emscripten target for wasm-bindgen. When you run entire software build and deployment systems in tight loops on Workers, the benefits of a small memory footprint pay off quickly.

reply
TheMrZZ 3 hours ago
The success of "modern" CLI tools written in Rust (uv, oxlint, turbopack) show there's a clear demand for faster tools in general.

Also, faster feedback loop is crucial for AIs, so I guess this makes sense.

reply
pjmlp 3 hours ago
What they show is that JavaScript should never have left the browser into the backend.

Don't rewrite into Rust, Go, Java, .NET, Zig, Odin, whatever.

Start with them directly.

reply
eterm 3 hours ago
Faster feedback loops almost always deliver improvements elsewhere.
reply
mohammedalfarra 3 hours ago
[flagged]
reply
kidby 3 hours ago
[dead]
reply
Rapzid 3 hours ago
Up to 8x faster seems kinda of a crazy claim. 8x faster at what?! TS 7.0 is reasonably well optimized and compiles VSCode in well under 10 seconds..

This can type check and compile VSCode in less than a second?

reply
lemagedurage 2 hours ago
For VSCode: 4x speedup vs TS 7, 3x vs TS 7.1
reply
rs_rs_rs_rs_rs 2 hours ago
Yes, it's in the article.
reply
magicalist 2 hours ago
Well, no, not exactly. The article says vscode is compiled in 5.28s in typescript 7.1 (nightly), and in 1.73s in tsrs (dev), which is 3x faster.
reply
Rapzid 2 hours ago
3x isn't so wild but still very impressive.
reply
norman784 3 hours ago
I'm tired of all the new tools that comes out every day, but I would say, this is basically the Vite team and if they implement it with Vite+, then I'm all for it, less decisions about tooling to be made, one config file, etc.
reply
jscheel 2 hours ago
I benchmarked tsrs a few weeks ago. I was testing out tsgo, ts-rust, tsrs, and bun for typechecking on our monorepo. tsrs is definitely awesome, it is very memory efficient when bumping up the number of threads. Not as efficient as bun, but it has incremental checks, which bun does not have.
reply
wannabe44 3 hours ago
Y'all building the same thing.
reply
frangonf 3 hours ago
I use oxc tooling and it's great to see the rust rewrite singularity in action and get to ride the fastest horses, but I would like that they made a branch for 7.2 as experiment to see how it compares. Maybe this ends in a win for Microsoft, they could cut operating expenses by keeping just Anders Hejlsberg in a hammock reciting invariants to claudpilot.
reply
nsm 3 hours ago
Obligatory reminder that their needs from a TS compiler are extremely different from a regular web developers iteration cycle. They are trying to run millions of these while saving on costs.

You almost definitely don't need to immediately plan to switch.

reply
cryptonym 3 hours ago
> This enables new possibilities when combined with agents: You are now able to run a development toolchain end-to-end in a fully sandboxed environment on Cloudflare.

True. Looks like main use-case is AI Agent Sandboxing

reply
g0ld3nrati0 28 minutes ago
so rust is now go-to slop language? can't you guys use C or something. I want rust back.
reply
jdw64 3 hours ago
These days the trend seems to be rewriting everything in Rust.
reply
zeroq 3 hours ago
I'm staying stainless
reply
satvikpendem 40 minutes ago
You should say you're staying fungal infection free as it's named after the Rust fungus not the chemical reaction even if that's what people think these days.
reply
jdw64 2 hours ago
Did you know? Even stainless steel RUSTs in sea wind.
reply
tonyhart7 3 hours ago
I thought its TS port of theo
reply
AntonyGarand 3 hours ago
Theo's port is tsc-rs[0] as reference, and is significantly slower and uses more memory than this new version.

[0] https://github.com/pingdotgg/ts-rust

reply
francislavoie 3 hours ago
A new one but they're merging it with Theo's.
reply
souvlakee 2 hours ago
[dead]
reply
nalekberov 3 hours ago
Oh god, I wish this Rust fetishism would end soon.
reply
retropragma 3 hours ago
please support TSRX (https://github.com/tsrx-org/tsrx)
reply