MacMusic  |  PcMusic  |  440 Software  |  440 Forums  |  440TV  |  Zicos
compiler
Search

TypeScript gets Go-faster stripes

Thursday March 20, 2025. 10:00 AM , from InfoWorld
Last week Microsoft announced a major shift in the architectural direction of its TypeScript language. Until now the TypeScript compiler, tsc, was written in TypeScript itself, compiled to JavaScript, and run on top of Node.js. However, it’s shifting to a stand-alone native binary compiler using the Go language.

This move means a considerable acceleration in compiling the large projects that TypeScript was designed to support, such as the cloud-hosted Office applications and the Visual Studio Code IDE. Microsoft’s announcement blog post suggested that code could be compiled more than 10 times faster than before.

A new compiler for TypeScript

The numbers certainly look good: Visual Studio Code’s 1.5 million lines of code take nearly 78 seconds to compile using the current tool, but the new native compiler comes in at only 7.5 seconds, which is 10.4 times faster. That’s a significant improvement. It means the development team can start to think about treating the new compiler much like.NET’s Roslyn, adding the ability to use the compiler inside your development tools to dynamically debug code as you write it or to work more closely with GitHub’s Copilot and similar tools.

Speed is the key to these new capabilities; they need a native compiler rather than one running inside a JavaScript engine. Having the compute capabilities to dig down into your code as you write it will make TypeScript more accessible and improve both developer productivity and satisfaction. As we’re being encouraged to be more productive, getting the necessary compiler-level support to, say, refactor across the entire Visual Studio Code code base is essential.

Speeding up the TypeScript compiler by a factor of 10 will make it easier for an editor language server to provide the information needed to highlight code and track brackets and semicolons. At the same time, tools such as IntelliSense will be able to deliver more accurate code completions. Part of the work in this update adds support for the Language Server Protocol, which will allow more IDEs and programmer’s editors to add support for TypeScript.

Microsoft is noting significant improvements in memory usage. By removing the overhead that comes with running a compiler on a just-in-time platform, there’s already about 50% improvement, and that’s before the team adds its own optimizations.

Less memory overhead impacts tools and the environments to build TypeScript applications. With more and more organizations shifting to virtual environments such as GitHub Codespaces and Azure Dev Spaces, being able to keep resource requirements to a minimum, even for the most complex projects, helps manage costs and ensure that virtual environments load as quickly as possible.

Developing TypeScript-Go in public

These are early days for the new TypeScript compiler, and development is running in parallel with the next releases of the familiar JavaScript-based tool. The release notes show that even though much of what we need is ready, there’s still a lot missing. As a result, the next minor and major releases of TypeScript (5.9 and 6.x) will still be built on the current platform. However, as the new compiler adds enough features to support TypeScript 6.x code, it will be released as TypeScript 7.0. You can think of this as a similar migration as.NET’s away from the.NET Framework or PowerShell’s to being built on.NET; Microsoft will keep old and new TypeScript under development until it’s time for the new to leave the old behind.

There have been criticisms that it won’t be possible to run the new compiler as part of a web-based playground. But as the language’s designer, Anders Hejlsberg, notes in a GitHub comment, there is the possibility of using a WebAssembly version of the Go compiler to continue to support web-based development—and to offer many of the new compiler features to web code playgrounds.

Development is happening in the open on GitHub in a separate repository from the JavaScript release. For now, there isn’t a public binary release, but that doesn’t stop you from taking the current code base and compiling your own tools to give it a try. Microsoft provides instructions for building the Go-based TypeScript compiler, as well as the related Language Server with support for Visual Studio Code.

Build it yourself

Building the new TypeScript compiler and language server is relatively straightforward. You’ll need to install a few prerequisites before getting started: an up-to-date version of the Go compiler, as well as the Node.js JavaScript platform and the hereby task runner. If you’ve not used hereby before, it’s a Node.js-based tool for chaining tasks together and is used to orchestrate the TypeScript build process. Different runners are available for different outputs: one to build the compiler, one to build the tests, one to make sure the code is properly linted, and more.

Technically you don’t need to use hereby and can work with Go’s own tool, but using hereby does simplify things. One important point, if you haven’t installed hereby as a global tool, you can use npm’s npx command to launch and run the task runner. So, instead of using hereby build to run a build, simply use npx hereby build. This gives you the same output without the complexity of editing paths.

To get started, first clone the TypeScript-Go GitHub repository along with the submodules. This was an issue on a Windows system, as the path lengths for the submodules were too long. However, I was able to install them later using Git’s submodule update command. This allowed me to use npx hereby test to run TypeScript-Go’s tests once I’d completed a build.

With the prerequisites installed, building the Go-based TypeScript is straightforward. Running npx hereby build installed the experimental tsgo compiler in a built directory alongside the source code. Once the build was complete, I checked it by running the provided tests. Although there isn’t a complete set of tests yet, those that do exist give a good feel for how well the compiler performs. The current suite passed in just over 3 minutes 30 seconds on my test hardware.

A compiler plus a new language server

The new tools include a first pass at delivering a language server for the new compiler. It’s not hooked up to any new development tool yet, but you can install it in Visual Studio Code to see how well it performs at parsing changes to your TypeScript code by looking at its outputs in the Code debugger.

Microsoft provides installation instructions in Visual Studio Code, with the required JSON as part of the GitHub repository. I found this part of the documentation a little confusing and initially misread it as implying that the configuration JSON was generated as part of the build process. When I couldn’t find the necessary files in the built folders, I reread the documentation and realized they were cloned along with the source code for the compiler and language server.

Once I got over that hurdle, I could see language server output in Visual Studio Code, running in extension development mode. This approach will allow third-party extension developers to hook into the TypeScript-Go language server and build their own extension tools on top of the new compiler. What’s there is responsive, firing up events when you make changes to TypeScript in the Code editor window, with outputs shown in the Output pane, when selecting either typescript-go or typescript-go (LSP).

It’s good to see Microsoft investing in developer productivity in its compilers. The recent resurgence of.NET is as much due to its Roslyn compiler as to improvements in its languages and UI tooling, and it looks as though these TypeScript updates offer many of the same benefits. Having a fast compiler is key to getting value from modern development tools, as we can use them to deliver real-time error corrections and provide the deep understanding of compiled code necessary to get the most from techniques like refactoring.

With development in the open, we’re already seeing pull requests coming in from the community to improve performance in other areas of the platform. It’s an excellent sign to see outside involvement this early in a project of this scale, as it shows both community buy-in to the reengineering of TypeScript and the popularity and utility of the platform itself.

TypeScript has become an essential tool for Microsoft, as it powers both Visual Studio and the web versions of its Office suite. This new compiler will make it easier for Microsoft’s own development teams to deliver high-quality code, and we can all take advantage of it in our own applications—moving our own large JavaScript applications to a strongly typed, easier-to-manage language that shares much of the same syntax. Microsoft may be solving its own problems here, but when Redmond’s developers get to be more productive, so do we.
https://www.infoworld.com/article/3849654/typescript-gets-go-faster-stripes.html

Related News

News copyright owned by their original publishers | Copyright © 2004 - 2025 Zicos / 440Network
Current Date
Mar, Mon 31 - 15:31 CEST