Microsoft Rewrites TypeScript with Go: A 10x Speed Boost and the Reasoning Behind It
On March 11, 2025, Microsoft unexpectedly announced a complete rewrite of TypeScript using the Go programming language. This resulted in a reported 10x speed improvement, causing considerable excitement in the tech community. The magnitude of the change and its impact represent a significant upgrade in programming language history. It's important to clarify that the 10x speedup refers to compilation time, not runtime performance of the JavaScript code generated by TypeScript.
The Focus on Compilation Speed
While the speed of the compiled JavaScript is determined by the JavaScript engine, the improved compilation time is a major win for developers. Reduced compilation times translate to faster development cycles and greater efficiency. This makes the development experience smoother and more productive.
Why Go and Not Rust or C#?
The central question following the announcement wasn't about the technical challenges of achieving a 10x speedup or the intricacies of such a large-scale language upgrade. Instead, the community wondered why Go was chosen over Rust or Microsoft's own C#. Why Go, a language from rival Google, over C#, created by TypeScript's own founder, Anders Hejlsberg?
Project Management and Technical Choices
The answer lies in the technical considerations of language selection and project management decisions. Let's delve into the reasons behind choosing Go for this significant TypeScript upgrade.
Native Port vs. Rewrite: Project Goals
According to Anders Hejlsberg, the initial goal was a Native Port rather than a complete Rewrite. A Native Port involves translating each function in the original TypeScript source code into its equivalent in the new language. This approach preserves the overall structure and logic, resulting in high development efficiency and maintaining feature parity. This ensures compatibility for existing projects, enabling seamless upgrades.
A complete Rewrite, on the other hand, requires rebuilding TypeScript from scratch using a new language. This would involve significantly more work and potentially lead to backward compatibility issues, similar to the challenges faced during the Python 2 to 3 transition, which took a decade to resolve. The new Go-based version of TypeScript is planned to be named TypeScript 7. The existing JavaScript-based TypeScript 5.8 will continue to be updated to 5.9, eventually becoming TypeScript 6.
Maintaining Compatibility
The goal of TypeScript 6 is to ensure a high degree of consistency with TypeScript 7, except for the underlying language. This allows most users to seamlessly upgrade from the JavaScript-based core of version 6 to the Go-based core of version 7, with the exception of projects relying on specific JavaScript interfaces or legacy features.
Why Not Rust? Garbage Collection Considerations
The primary reason for not choosing Rust is the need to maintain complete feature parity during the language port. This includes the garbage collection (GC) mechanism. JavaScript's GC uses a mark-and-sweep approach. Go's GC mirrors this approach, using the same principle, but with faster execution due to multithreading.
Rust, however, uses a different memory management model based on ownership and lifetimes. This eliminates the need for automatic GC but requires manual memory management. This difference creates challenges when dealing with circular data structures, which are common in TypeScript. In Rust, complex pointer rules would be required to replicate functionality that Go achieves with its GC model, making a one-to-one translation impossible.
Functional Programming and the Speed of Development
Hejlsberg started prototyping the project himself, porting two core components to Go in just over a month. This rapid progress was possible because TypeScript's code is written in a functional programming style. Nearly the entire codebase consist of function without classes. Functional programming is conducive for code transfer, since the function can be transferred and it will work without interfering with other code.
Go vs. C#: Functional Programming Preference
The decision to use Go over C# boils down to programming paradigms. TypeScript, Go, and Rust are modern languages that lean towards functional programming. C#, while also a modern language, caters more to enterprise-level scenarios and is designed to be compatible with the object-oriented .NET framework.
A Process of Elimination: Why Go Was the Best Choice
The language selection process can be seen as a process of elimination:
- Maturity and Ecosystem: The language must be mature with a rich ecosystem and broad hardware compatibility.
- Performance: A compiled language is needed for performance reasons.
- Functional Programming: The language should support functional programming to facilitate code replication.
- Core Mechanism Parity: The core mechanisms, particularly garbage collection, must be similar.
These criteria narrowed the field to Go.
The 10x Speed Boost: Compilation and Multithreading
The 10x speed boost results from two main factors. First, Go, as a compiled language, is inherently faster than TypeScript, an interpreted language. Internal testing revealed a 3x speedup from this alone. Second, Go's multithreading capabilities allow it to leverage modern CPUs more effectively than TypeScript's single-threaded execution.
TypeScript primarily operates in the development and compilation phases and mostly processes data for type checking. Go's multithreading significantly enhances performance. Hejlsberg mentioned that internal tests with 32-core CPUs showed potential speed improvements of up to 100x.
The Future: AI-Assisted Development
The increased speed opens new possibilities for AI-assisted development. While AI is already used in development, the interaction is currently limited by the text-based code input. With a 100x speed boost, the new TypeScript can provide AI with comprehensive context information, such as type definitions, function call chains, and code structure. This could significantly enhance AI-assisted development features.