Announcing: A Free Book, A New Course, A Huge Price Cut...
It's a massive ship day. We're launching a free TypeScript book, new course, giveaway, price cut, and sale.
You'll often find folks talking about "TypeScript Performance". They might say "my codebase feels slow" and that "TypeScript is making my editor slow".
What do they mean?
TypeScript performance is a measure of how fast TypeScript can type-check your codebase. It's a measure of how quickly your editor can provide feedback on your code.
It's NOT a measure of how fast your code runs. TypeScript is a compile-time tool, not a runtime tool. Simply using TypeScript will not change the speed at which the emitted JavaScript runs - TypeScript doesn't do anything at runtime.
When TypeScript performance is poor, you will notice:
In other words, the things you do every day become slower and more painful.
TypeScript performance can be affected by several factors.
The first is scale. Simply put, the more code TypeScript needs to check at once, the slower it will run. However, scale is often less of a factor than you might think.
The second factor is the way you write your code. Using intersections instead of interfaces, utilizing project references, and employing return types judiciously are all useful ways to address TypeScript performance issues.
The TypeScript Performance Wiki provides a great list of strategies you can use to improve your TypeScript performance.
You can use some tsc
flags to measure your TypeScript performance.
Using tsc --diagnostics
or tsc --extendedDiagnostics
will provide you with information about how long it takes TypeScript to type-check your codebase.
By running tsc --generateTrace ./outDir
, you can generate a trace file that can be opened in Chrome's Trace Viewer to see where TypeScript is spending its time.
Aleksandra Sikora's excellent talk at BeJS is a great resource to begin exploring this topic.
Share this article with your friends
It's a massive ship day. We're launching a free TypeScript book, new course, giveaway, price cut, and sale.
Learn why the order you specify object properties in TypeScript matters and how it can affect type inference in your functions.
Learn how to use corepack
to configure package managers in Node.js projects, ensuring you always use the correct one.
Learn how to strongly type process.env in TypeScript by either augmenting global type or validating it at runtime with t3-env.
Discover when it's appropriate to use TypeScript's any
type despite its risks. Learn about legitimate cases where any
is necessary.
Learn why TypeScript's types don't exist at runtime. Discover how TypeScript compiles down to JavaScript and how it differs from other strongly-typed languages.