Big TypeScript performance update: 10x faster compiler using Go
Porting from TypeScript to Go
Microsoft is rewriting the TypeScript compiler (tsc
) in Go to improve performance. The current TypeScript compiler is written in TypeScript itself, which runs on Node.js. While this makes it easier to maintain, it is relatively slow because JavaScript is single-threaded and interpreted.
The new approach compiles TypeScript source code using a Go-based compiler instead of relying on JavaScript. This transition allows the compiler to leverage Go’s native performance benefits, optimizing parsing, type checking, and build times.
Why use Go?
Microsoft chose Go for several reasons:
- Familiar syntax: Go’s structure is similar to TypeScript, making the transition easier.
- Memory management: Go provides efficient memory handling without manual intervention.
- Concurrency: Go’s built-in concurrency features allow multiple tasks (like parsing and type checking) to run simultaneously.
What makes it so fast?
The speed improvements come from:
- Go’s compiled nature: Unlike JavaScript, which is interpreted, Go is compiled, leading to faster execution.
- Multithreading: The new compiler can perform tasks in parallel, whereas the old compiler was limited by JavaScript’s single-threaded execution.
- Optimized algorithms: The Go implementation takes advantage of more efficient data structures and processing techniques.
Preliminary benchmarks of the native Go implementation demonstrate substantial performance gains across various codebases:
Codebase | Size (LOC) | Current tsc Time | Native tsc Time | Speedup |
---|---|---|---|---|
VS Code | 1,505,000 | 77.8s | 7.5s | 10.4x |
Playwright | 356,000 | 11.1s | 1.1s | 10.1x |
TypeORM | 270,000 | 17.5s | 1.3s | 13.5x |
date-fns | 104,000 | 6.5s | 0.7s | 9.5x |
tRPC | 18,000 | 5.5s | 0.6s | 9.1x |
rxjs | 2,100 | 1.1s | 0.1s | 11.0x |
Benefits of TypeScript-Go
The switch to Go brings several improvements:
- Faster compile times: Up to 10x faster project builds.
- Better editor performance: VS Code and other IDEs will have quicker IntelliSense and faster startup times.
- Reduced memory usage: More efficient memory allocation leads to lower resource consumption.
- Smoother development workflow: Faster feedback loops mean increased productivity for developers.
Microsoft’s TypeScript-Go project is a major step toward making TypeScript development faster and more efficient. As the project progresses, developers can expect significant improvements in performance and usability.