A 10x faster TypeScript

Microsoft Developer
11 Mar 202513:45

Summary

TLDRAnders Hejlsberg, lead architect of TypeScript at Microsoft, introduces Project Corsa, an initiative to port the TypeScript compiler to native code for significant performance improvements. By moving to Go, the project achieves faster builds, improved memory management, and concurrency support, making the compiler up to 10x faster. This port preserves the same functionality while addressing challenges like memory issues in large projects. The new compiler offers faster project loads and is paving the way for AI-assisted features. Expect a fully functional native compiler and language service by the end of the year.

Takeaways

  • 😀 Anders Hejlsberg, the lead architect of the TypeScript project, discusses the Corsa project to port the TypeScript compiler to native code for improved performance.
  • 😀 The TypeScript compiler has been written in TypeScript since its inception, but performance issues and memory constraints have led to the decision to move to native code.
  • 😀 JavaScript's runtime platform is optimized for UI and browser usage, not for compute-intensive tasks like compilers, which creates challenges such as memory overflow and overhead.
  • 😀 The main goal of the Corsa project is to port the existing TypeScript compiler (lock, stock, and barrel) to Go, a language that provides optimized native code support and concurrency.
  • 😀 The new native code compiler in Go is significantly faster, completing tasks like compiling the Visual Studio Code project over 10x faster than the existing TypeScript-based compiler.
  • 😀 Corsa maintains the exact semantics of the TypeScript compiler by porting function-by-function, ensuring that behaviors such as type inference are preserved.
  • 😀 The new compiler also offers a faster language service, including faster project load times and error checking, as seen with the Visual Studio Code project, which loads about five times faster.
  • 😀 A key performance improvement comes from leveraging concurrency: instead of running a single type checker, the compiler uses multiple type checkers working in parallel to speed up the process.
  • 😀 The ported compiler takes advantage of Go’s native memory management and concurrency capabilities, allowing for better performance while reducing memory consumption compared to the previous JavaScript-based version.
  • 😀 The Corsa project is still under development, with an 80% complete command-line compiler, support for basic language services, and plans to expand features such as incremental compile, JS/JSX support, and AI-assisted capabilities.

Q & A

  • What is Project Corsa and why is it important for TypeScript?

    -Project Corsa is an effort to port the TypeScript compiler and toolset to native code. This initiative aims to improve performance and resolve issues like memory limitations that arise from using JavaScript for compute-intensive tasks such as compilation.

  • What performance challenges did TypeScript face with its JavaScript-based compiler?

    -The TypeScript compiler, written in JavaScript, faced performance challenges due to JavaScript's overhead, including JIT compilation costs, the flexible object model, and the lack of shared memory concurrency. These limitations resulted in slower compilation times and out-of-memory issues as projects grew larger.

  • How did the new native code compiler improve performance?

    -The new native code compiler, written in Go, demonstrated a dramatic performance boost, compiling the Visual Studio Code project more than 10 times faster than the existing JavaScript compiler, reducing compile times from about a minute to just 5-6 seconds.

  • Why was Go chosen as the language for porting the TypeScript compiler?

    -Go was chosen because it offers low-level control over data layout, native code optimization, automatic memory management with a garbage collector, and efficient concurrency. These features made Go the most suitable choice for handling TypeScript’s compiler workload across all platforms.

  • What are the key differences between the old and new TypeScript compilers?

    -The new compiler is a port of the old one, meaning the same functionality and behavior are preserved, but the implementation is now in Go. The new compiler offers significant performance improvements, including faster compilation times and better memory management, particularly through concurrency.

  • How does the new TypeScript compiler handle concurrency?

    -The new compiler uses concurrency to improve performance. Parsing and binding files are fully parallelized, allowing the compiler to process multiple files at the same time. Type checking is split across multiple type checkers, improving speed without significantly increasing memory usage.

  • What new features are being introduced with the native language service?

    -The new language service, built on the Language Server Protocol (LSP), improves code navigation and error reporting. Features like hover, go to definition, and real-time error highlighting are implemented more efficiently, and the language server restarts are much faster, benefiting larger projects.

  • How much faster is the new language service compared to the old one?

    -The new language service is approximately five times faster at loading and providing semantic errors compared to the old one. It can parse 4,500 files and display errors in under three seconds, significantly improving the developer experience.

  • What are the potential AI-driven improvements for TypeScript in the future?

    -The performance improvements from Project Corsa open up opportunities for AI-assisted features, such as immediate type checking of a large language model's output, as well as providing semantic information in prompts, which could enhance refactorings and other intelligent code analysis.

  • What is the current status of Project Corsa, and what features are still being developed?

    -Project Corsa is about 80% complete, with the core compiler functioning well. Features like support for JavaScript, JSX, and incremental compilation are still in progress. The language service is also under development but is not yet fully mature. A fully functional replacement command-line compiler is expected within the year.

Outlines

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now

Mindmap

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now

Keywords

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now

Highlights

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now

Transcripts

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now
Rate This

5.0 / 5 (0 votes)

Related Tags
TypeScriptProject CorsaNative CodeCompilerPerformanceAI FeaturesMicrosoftGo LanguageConcurrencyLanguage ServiceMemory Management