TypeScript 7 Performance Gains via Go Port
Better Stackgo watch the original →
the gist
TypeScript 7 replaces the JavaScript-based compiler with a Go implementation, leveraging multi-core concurrency and shared memory to achieve up to 15x faster build times.
The Compiler Shift to Go
TypeScript 7 transitions the compiler from JavaScript to Go to overcome the single-threaded limitations of the Node.js runtime. JavaScript is optimized for UI and I/O-bound tasks, making it inefficient for CPU-intensive operations like parsing large abstract syntax trees or complex type checking. By porting to Go, the compiler gains native execution speed and a robust concurrency model that utilizes shared memory, allowing the tool to scale across all available CPU cores without the overhead of serializing data between workers.
Performance and Concurrency
The new compiler architecture distributes type-checking workloads across multiple threads. Users can manually tune this concurrency using the --checkers flag to match their machine's core count. For example, setting --checkers 12 allows the compiler to parallelize the type-checking phase significantly, reducing build times for massive codebases like VS Code from over two minutes to just a few seconds. Beyond raw build speed, the language server has seen substantial stability improvements, with an 80% reduction in failing commands and a 60% decrease in server crashes.
Implementation Details
- Native Concurrency: The compiler uses Go's runtime to manage thread distribution, avoiding the need for manual thread spawning or complex inter-process communication.
- Shared Memory: Unlike JavaScript workers that require serializing objects into raw bytes, Go allows the compiler to pass complex data structures between threads directly.
- Configuration: Users can optimize performance by explicitly setting the number of checkers, such as
tsc --checkers 12. - Compatibility: The release is a port rather than a rewrite, maintaining full compatibility with existing TypeScript projects, though programmatic API support for tools like
ts-eslintorts-nodeis pending in the 7.1 release.
Before / After
- VS Code (1.3M lines): 125.7 seconds (TS 6) vs 10.6 seconds (TS 7).
- Blue Sky: 24.3 seconds (TS 6) vs 2.8 seconds (TS 7).
- Playwright: 12.8 seconds (TS 6) vs 1.5 seconds (TS 7).
- Local M3 Max Test: 45.3 seconds (TS 6) vs 3.5 seconds (TS 7).