读见

Cloudflare 与 VoidZero 推出 tsrs:一个由 AI 生成的 TypeScript Rust 移植版

原题Cloudflare and VoidZero Introduce tsrs: An AI-Generated Rust Port of TypeScript

约 2 分钟约 487 字原文英文已翻译

读前速览

5 个要点

Cloudflare 与 VoidZero 发布了 tsrs,这是一个由 AI 生成的 TypeScript Rust 移植版,声称类型检查速度最高提升 8 倍、内存占用减少 70%,使用 Claude Opus 5.5 智能体开发,零手写代码,并以 TypeScript 的一致性测试套件作为规范。

  1. tsrs 是一个由 AI 生成的 TypeScript Rust 移植版,类型检查速度最高提升 8 倍、内存占用减少 70%,使用 Claude Opus 5.5 智能体开发,零手写代码。

    Max Schwenk 指挥 AI 智能体完成移植,并以 TypeScript 的 15,197 个一致性测试用例作为规范。在 Owner 的 37,000 文件单体仓库上,一次需要 19 GiB 内存和 80 秒的检查降至 7 秒。独立基准测试确认了 5.3 倍加速和 72% 内存减少,诊断结果完全一致,输出字节级相同。

  2. tsrs 支持无垃圾回收器的 WebAssembly 编译,相比基于 Go 的替代方案在部署上更具优势。

    @tsrs/wasm 包允许在浏览器或 Cloudflare Workers 上运行类型检查,而不会像 Go 二进制文件那样将垃圾回收器拖入打包产物。这解决了边缘计算环境中的特定部署约束。

  3. 该项目并非分支——微软 TypeScript 团队保留对语言设计的完全控制权,tsrs 中的优化正反馈回 TypeScript 7.1。

    TypeScript 团队的 Daniel Rosenwasser 指出,速度提升很大程度上并非仅取决于语言选择,tsrs 中发现的一些优化正被纳入官方 TypeScript 7.1 版本,体现了合作而非竞争的态势。

  4. tsrs 仍处于实验阶段,存在显著限制,包括不支持监视模式、语言服务器支持以及完整的 tsconfig 兼容性。

    当前缺口包括缺少 --init 和 --showConfig 标志、诊断顺序可能存在差异,以及 CI 退出码不兼容(tsrs 退出码为 2,而 tsc 为 1)。使用 TypeScript 5 或 6 的团队应首先采用微软的原生 Go 移植版,再考虑 tsrs。

  5. Cloudflare 正在将 tsrs 与 Theo Browne 的竞争项目 tsc-rs 合并为一个统一包,以整合各方努力。

    Cloudflare 并未选择竞争,而是宣布计划将两个基于 Rust 的移植版合并,增加语言服务器和内容映射器支持,这标志着业界围绕这一 TypeScript 工具链方案的整合趋势。

完整摘要

tsrs 是一个基于 Rust 的 TypeScript 类型检查器,由 Cloudflare 与 VoidZero 及 Max Schwenk 合作开发,孵化于 Oxc 工具链中,并与微软 TypeScript 团队密切合作。该项目声称相比 TypeScript 7.0,类型检查速度最高提升 8 倍,内存消耗减少约 70%,并可通过 @tsrs/wasm 编译为 WebAssembly,且不引入垃圾回收器。据报道,Schwenk 本人未编写任何一行代码,而是指挥由 Claude Opus 5.5 主导的 AI 智能体完成移植,并以 TypeScript 的 15,197 个一致性测试用例作为规范。在 Owner 的 37,000 文件单体仓库上,一次需要 19 GiB 内存和 80 秒的检查降至 7 秒。独立基准测试测得 5.3 倍加速和 72% 内存减少,诊断结果完全一致,但注意到 CI 退出码存在差异(tsrs 退出码为 2,而 tsc 为 1)。TypeScript 团队的 Daniel Rosenwasser 指出,在 tsrs 中发现的优化正被纳入 TypeScript 7.1,Cloudflare 正在将 tsrs 与 Theo Browne 的 tsc-rs 合并为一个统一包。该版本仍处于实验阶段,缺少监视模式、语言服务器支持以及完整的 tsconfig 兼容性。

查看原文

Cloudflare 宣布推出 tsrs,这是 TypeScript 编译器的 Rust 移植版。该项目由 Cloudflare 与 VoidZero 以及 Owner.com 的 Max Schwenk 共同开发,在 Oxc 工具链中孵化,并与 TypeScript 团队密切合作。Cloudflare 强调,这并不是一个分叉版本,TypeScript 团队仍完全掌控该语言的设计。tsrs, a Rust port of the TypeScript compiler, has been announced by Cloudflare, which is developing it with VoidZero and Max Schwenk of Owner.com, incubating the project inside the Oxc toolchain and working in close collaboration with the TypeScript team. Cloudflare is emphatic that this is not a fork, with the TypeScript team retaining full control over the language's design.

Cloudflare's benchmark comparing tsrs against TypeScript 7.0 at the same number of checker workers

Cloudflare 在检查器工作线程数量相同的情况下,对比 tsrs 与 TypeScript 7.0 的基准测试Cloudflare's benchmark comparing tsrs against TypeScript 7.0 at the same number of checker workers

主要宣传数据是:在检查器工作线程数量相同的情况下,类型检查速度最高可达 TypeScript 7.0 的 8 倍,内存占用约减少 70%。Rust 还解锁了通过 @tsrs/wasm 编译为 WebAssembly 的用例,因此可以在浏览器或 Workers 上运行检查,而不必像 Go 二进制文件那样把垃圾回收器也带进打包文件中。The headline numbers are a claimed up to 8x faster type checking and around 70% less memory than TypeScript 7.0 at the same number of checker workers. Rust also unlocks the use case of compiling to WebAssembly through @tsrs/wasm so checks can run in a browser or on Workers, without dragging a garbage collector into the bundle the way a Go binary does.

要试用它,开发者只需将其指向一个现有的 tsconfig 并运行:To try, developers simply point it at an existing tsconfig and run:

npm install -D tsrs
npx tsrs -p . --noEmit

在一篇详细文章中,Schwenk 解释说,他自己“零”代码,而是指挥由 Claude Opus 5.5 领头的智能体,以 TypeScript 自身的 15,197 个一致性测试用例为规范,开发出忠实的移植版本。在 Owner 那个包含 37,000 个文件的单体代码库上,TypeScript 7.0 原本需要 19 GiB 内存和 80 秒才能完成的检查,如今只需 7 秒。In a detailed write-up, Schwenk explains he wrote "zero" code, instead directing agents led by Claude Opus 5.5 to produce a faithful port, using TypeScript's own 15,197 conformance cases as the spec. On Owner's 37,000-file monolith, a check that needed 19 GiB and 80 seconds on TypeScript 7.0 dropped to 7 seconds.

一位开发者对两个 npm 包都进行了基准测试,测得检查速度快了 5.3 倍、内存占用少了 72%,而诊断结果相同、生成内容逐字节一致;但他发现,tsrs 遇到类型错误时会以代码 2 退出,而 tsc 会以代码 1 退出,这足以悄无声息地导致 CI 脚本失效。以较新的 TypeScript 7.1 beta 而非 7.0 为基准进行测试时,ImportStatic 发现性能提升幅度较小,为 2.7 倍,这也提醒我们,标题中宣称的 8 倍提升是以较旧版本为基准测得的。One developer benchmarked both npm packages and measured 5.3x faster checking and 72% less memory, with identical diagnostics and byte-identical emit, but spotted that tsrs exits with code 2 on type errors where tsc exits 1, enough to quietly break a CI script. Measuring against the newer TypeScript 7.1 beta rather than 7.0, ImportStatic found a smaller 2.7x gain, a reminder that the 8x headline is measured against the older baseline.

TypeScript 的 Daniel Rosenwasser 回应称,速度优势“并不只是语言选择带来的”,而且在 tsrs 中发现的一些优化正在融入更精简的 TypeScript 7.1。Peter Steinberger 在 X 上报道称:TypeScript's Daniel Rosenwasser responded that much of the speed "does not just come down to language choice," and that some optimisations discovered in tsrs are feeding into a leaner TypeScript 7.1. Peter Steinberger reported on X:

周末迁移到了 tsrs。可以直接替换原来的方案。OC 的速度快了大约 5 倍。挺不可思议的:微软花了一个团队、两年时间用 Go 重写 TS 编译器,而现在你只要放手让智能体大干一场,几周内就能做出明显更好的东西。

Moved to tsrs over the weekend. Drop-in replacement. Around 5x faster for OC.

Kind of amazing that it took Microsoft a team and two years to rewrite the TS compiler in go, and now you can just let an agent rip and get sth significantly better within weeks.

其他人则持怀疑态度,质疑基于 arena 且永不释放内存的模型是否可靠。Others were wary, questioning whether the arena-based, never-freed memory model is sound.

tsrs 与微软自家的 Go 编译器 tsgo,以及 Theo Browne 的 Rust 移植版竞品 tsc-rs 并列。Cloudflare 并未让它们相互竞争,而是将 tsc-rs 和 tsrs 合并为一个软件包,并加入对语言服务器和内容映射器的支持。tsrs sits alongside Microsoft's own Go-based compiler, known as tsgo, and Theo Browne's rival Rust port, tsc-rs. Rather than compete, Cloudflare is merging tsc-rs and tsrs into a single package, adding language server and content mapper support.

该版本仍处于实验阶段。目前还没有监视模式或语言服务器,--init 和 --showConfig 也不受支持,而且诊断信息的顺序可能有所不同。更多详情请参阅兼容性说明。由于 tsrs 跟进的是 TypeScript 7,仍在使用 TypeScript 5 或 6 的团队应先采用微软原生的 Go 移植版本,再换用 tsrs;之后迁移只需沿用现有的 tsconfig。The release remains experimental. There is no watch mode or language server yet, --init and --showConfig are unsupported, and diagnostic order can differ, the compatibility notes provide more details. Because tsrs tracks TypeScript 7, teams still on TypeScript 5 or 6 should first adopt Microsoft's native Go port before swapping in tsrs, after which migrating is as simple as reusing the existing tsconfig.

tsrs 采用 Apache-2.0 开源许可证,托管于 GitHub。tsrs is open source under Apache-2.0 and available on GitHub.

值得记下

  1. 周末切换到了 tsrs。直接替换。对 OC 来说大约快 5 倍。
  2. 速度提升很大程度上并非仅取决于语言选择。
  3. tsrs 与微软自家的基于 Go 的编译器 tsgo 以及 Theo Browne 的竞争性 Rust 移植版 tsc-rs 并存。
  4. 该版本仍处于实验阶段。目前没有监视模式或语言服务器,不支持 --init 和 --showConfig,诊断顺序也可能不同。