ITADN

Rewrite the Svelte compiler in Rust

#18376Openjwerre 创建于 2026-06-03
J
jwerrecommented
### Describe the problem With the React team's experimental Rust port of the React Compiler ([facebook/react#36173](https://github.com/facebook/react/pull/36173)), now is a good time to consider the same for Svelte. The React port has shown real numbers: the transformation logic runs roughly 10x faster than the TypeScript version, with an overall 3x speedup even after accounting for serialization overhead. Svelte's compiler runs at build time for every project that uses it, so its performance directly affects developer experience at scale. Cold builds, watch mode, and editor tooling all depend on it. Rust is now the go-to for high-performance JavaScript tooling: OXC, SWC, Rolldown, and the React Compiler have all made the move. Specific benefits for Svelte: - **Build performance:** Faster compilation for large component trees and monorepos. - **Editor integration:** A faster compiler core improves the Svelte Language Server and IDE extensions like the official VS Code plugin. - **Native toolchain integration:** Direct integration with OXC and SWC pipelines, which are becoming the default in modern JavaScript toolchains. - **Memory efficiency:** Rust's ownership model gives fine-grained memory control, which helps in long-running build processes and watch mode. ### Describe the proposed solution The React team's port is a good starting point. They kept the same internal architecture (HIR, CFG, SSA passes) while adapting data representations for Rust's borrow checker, which shows a faithful port is possible without redesigning compiler semantics from scratch. They also expose a stable public AST interface (a Rust Babel AST) that Babel, OXC, and SWC integrations can target. Svelte could do something similar: expose a Rust-native AST interface while keeping shims for existing Vite/Rollup/webpack plugins. This is admittedly a significant undertaking, with a few ways to approach it: - **Full rewrite:** Port the entire compiler to Rust, maintaining feature parity with the TypeScript version. - **Incremental port:** Start with the most performance-sensitive passes (parsing, analysis) and leave code generation in TypeScript initially. - **Hybrid approach:** Keep the public-facing JS/TS API as a thin wrapper over a Rust core (similar to how React is handling Babel integration). An incremental or hybrid approach would let the team ship performance improvements earlier without blocking on full feature parity. ### Importance nice to have
5 条评论