News

Microsoft Ports TypeScript to Go for 10x Native Performance Gains

Microsoft is revamping its TypeScript programming language with a native compiler and toolset. This effort seeks to address performance challenges, especially in large codebases, by porting the existing TypeScript compiler from TypeScript/JavaScript to the native language, Go.

"The native implementation will drastically improve editor startup, reduce most build times by 10x, and substantially reduce memory usage," announced Anders Hejlsberg, lead architect of TypeScript and Technical Fellow at Microsoft, in a March 11 post. "By porting the current codebase, we expect to be able to preview a native implementation of tsc capable of command-line typechecking by mid-2025, with a feature-complete solution for project builds and a language service by the end of the year."

His reference to tsc concerns the command-line compiler for TypeScript, responsible for transpiling TypeScript code into JavaScript and performing type checking.

Currently, the tsc is written in TypeScript itself and runs on Node.js, which means it requires a JavaScript runtime to execute. The native port will be implemented in Go, a statically compiled language. This means the TypeScript compiler will be compiled into a binary that can run directly on an operating system without requiring a separate runtime environment.

And that means massive performance gains to solve thorny problems in big codebases like long load times and check times.

Even though the effort, dubbed Project Corsa, is in its early stages and not feature complete, Hejlsberg provided this table showing times to run tsc on some popular codebases of different sizes on GitHub.

Codebase Size (LOC) Current Native 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 (server + client) 18,000 5.5s 0.6s 9.1x
rxjs (observable) 2,100 1.1s 0.1s 11.0x

In a March 11 video, Hejlsberg revealed the dev team prototyped the porting effort in various languages but found Go to be the most suitable, citing its balance of low-level control, optimized native code support, garbage collection, and concurrency features as key factors. He also outlined the project's roadmap, which includes completing the command-line compiler with full feature parity, developing a new inter-process API, and exploring AI-powered features.

More about that choice is explained in a FAQ item titled "Why Go?" in the project's GitHub repo. Another FAQ explains "Why a port instead of a rewrite? What's the difference?"

Key takeaways from the FAQ include:

  • Go was chosen for performance reasons. The team evaluated other languages like Rust, C and C++, but found Go to be the best fit for their needs.
  • The existing TypeScript compiler is written in TypeScript. This creates a bootstrapping problem, which contributes to the performance issues.
  • Compatibility is a major concern. The team is working to ensure that the native port is as compatible as possible with existing TypeScript code and configurations.
  • The project is open source. The code is available on GitHub under the same license as the existing TypeScript codebase.
  • Incremental adoption is planned. The team recognizes that some projects may not be able to immediately switch to TypeScript 7.0 and will continue to maintain the 6.x line.
  • The Go port will initially focus on the compiler and language service. Other tools, such as the TypeScript website and playground, may be ported later.
  • There are challenges in replicating the exact behavior of the existing compiler. The team is working to minimize differences, but some discrepancies may exist.

"We're incredibly excited about the opportunities that this massive speed boost creates," Hejlsberg said in his DevBlogs post. "Features that once seemed out of reach are now within grasp. This native port will be able to provide instant, comprehensive error listings across an entire project, support more advanced refactorings, and enable deeper insights that were previously too expensive to compute. This new foundation goes beyond today's developer experience and will enable the next generation of AI tools to enhance development, powering new tools that will learn, adapt, and improve the coding experience."

He also outlined the versioning roadmap, which is summarized here:

  • Current & Upcoming Releases:
    • TypeScript 5.8 is the latest release, with TypeScript 5.9 coming soon.
    • The JavaScript-based TypeScript compiler will continue into the 6.x series.
    • TypeScript 6.0 will introduce deprecations and breaking changes in preparation for the native transition.
  • Native Transition & TypeScript 7.0:
    • Once the Go-based native compiler reaches feature parity, it will be released as TypeScript 7.0.
    • Naming convention: TypeScript 6 (JS) vs. TypeScript 7 (native).
    • Codenames: "Strada" (original TypeScript) and "Corsa" (native port effort).
  • Coexistence & Support Plan:
    • TypeScript 6 (JS) will be maintained alongside TypeScript 7 until the native version is stable and widely adopted.
    • Some projects may switch to TypeScript 7 immediately, while others may need TypeScript 6 due to API dependencies or legacy configurations.
  • Long-Term Goal:
    • Keep TypeScript 6 and 7 closely aligned to ensure a smooth transition.
    • Allow developers to choose between the JS-based and native versions based on their needs.

TypeScript debuted in 2012 as a statically typed superset of JavaScript designed to improve maintainability and scalability in large projects. It subsequently grew in importance and frequently ranked among the most loved and widely adopted languages in several survey-based examinations of programming language popularity. For example, just a few months ago we reported "TypeScript Tops New JetBrains 'Language Promise Index.'" Over the years, in some surveys, it also vaulted ahead of languages such as Python, C# and Java. Microsoft just last week shipped TypeScript 5.8, delaying a problematic conditional type-checking feature to v5.9. It's unclear if the port will help address problems such as that.

Go, often referred to as Golang, originated at Google in 2007 and was publicly released in 2009. It was designed to improve programming productivity in an era of multicore processors, large codebases, and networked systems. It has since gained popularity for its simplicity, efficiency, and built-in support for concurrency. The language is used in a variety of applications, from web servers and cloud services to system utilities and machine learning tools.

More information on Project Corsa will be provided in a March 13 AMA (ask me anything) event on the TypeScript Community Discord.

Meanwhile, there is much discussion about the new project, much of it centered around the choice of Go as opposed to Microsoft darlings like Rust. Daniel Rosenwasser, principal product manager for TypeScript, early today started a Hacker News discussion on the port, and TypeScript dev lead Ryan Cavanaugh did the same on Reddit.

From the latter: "In the end we had two options - do a complete from-scratch rewrite in Rust, which could take years and yield an incompatible version of TypeScript that no one could actually use, or just do a port in Go and get something usable in a year or so and have something that's extremely compatible in terms of semantics and extremely competitive in terms of performance."

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

Subscribe on YouTube