Docs on improving compilation speed
See original GitHub issueWith the --watch
flag on, a recompile of an existing file generally takes 4 seconds now in our project. This isn’t terrible at all, but the wait time has grown since we started using it.
I was wondering what factors affect incremental compilation speed? With TypeScript gaining widespread adoption, I think it’ll be very important to developer experience to have a doc page detailing the main contributors to incremental compilation time and ways to improve it.
P.S. Note I meant incremental compilation speed with --watch
, not a full recompile.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:20
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Improving Compilation Time of C/C++ Projects - Interrupt
The first and easiest thing to do to speed up builds is ensure you are building with multiple threads. Make, IAR, and Keil...
Read more >Improving the speed of incremental builds - Apple Developer
If compilation of a particular file takes significantly longer than other files, examine the file to see if header importation issues are causing...
Read more >Compilation Speed - 2.8.x - Play Framework
Improving Compilation Times. Compilation speed can be improved by following some guidelines that are also good engineering practice: §Use subprojects/modularize.
Read more >The Little Things: Speeding up C++ compilation
Thus the simplest, and usually also the biggest, way to speed up the compilation of your code, is to just #include fewer files....
Read more >What techniques can be used to speed up C++ compilation ...
Ideally, changing the visibility can improve compiler performance, link time optimizations (LTOs), and generated binary sizes. If you look at the STL header ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just did some simple benchmarks with
tsc --watch
, here are the results:tsconfig.json
only watches this file):Note: I padded out the file by basically copying & pasting a bunch of
console.log
statements.I’m also working on a project which has about 3MB of TypeScript code spread across many files. The incremental transpilation time is about 3-4 seconds as well, so it seems that 1MB of TypeScript code = 1 second of incremental transpilation time on my machine. This seem to indicate that there is a fairly linear relationship between the size of the code being watched and compile time (regardless of number of files that code is spread across).
Now I checked how this might be affected by imports:
index.ts
, not a true declarations file) = still slowSo there you have it, one definite way to make compilation faster is to factor out the code to separate packages with declaration files.
One interesting example is this change to the styled-components types, which increased compile time by 20x. Background discussion here: https://github.com/microsoft/TypeScript/issues/30663.
It would be interesting to explore why; I’d love some principles to avoid issues like that in my own code, and tools to find problematic types in general in large codebases. Issues aren’t always going to be caused by an obvious dependency upgrade like this.
https://github.com/microsoft/TypeScript/issues/31612 might also be interesting, as another catastrophic performance case that docs/tooling should warn you about, and show you how to avoid.