question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docs on improving compilation speed

See original GitHub issue

With 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:open
  • Created 7 years ago
  • Reactions:20
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
ghostcommented, Sep 29, 2016

Just did some simple benchmarks with tsc --watch, here are the results:

  • Editing & saving a single TS file (tsconfig.json only watches this file):
    • 11KB = really fast
    • 3MB = ~3 seconds
    • 6MB = ~6 seconds

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:

  • Saving a small TS file importing a 4MB file = slow (~4 seconds)
  • Saving a small TS file importing a small file which imports a 4MB file = still slow
  • Saving a small TS file importing an external package with large typings file (well just index.ts, not a true declarations file) = still slow
  • Saving a small TS file importing an external package with small typings file for a large codebase = very fast

So there you have it, one definite way to make compilation faster is to factor out the code to separate packages with declaration files.

0reactions
pimterrycommented, Aug 12, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found