microsoft / microsoft/TypeScript
Ideas for faster cold compiler start-up
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Background
For some users, cold compile times are getting to be a bit long - so much so that it's impacting people's non-watch-mode experience, and giving people a negative perception of the compiler.
Compilation is already a hard sell for JavaScript users. If we can get some speed wins, I think it'd ease a lot of the pain of starting out with TypeScript.
Automatic skipDefaultLibCheck
lib.d.ts is a pretty big file, and it's only going to grow. Realistically, most people don't ever declare symbols that conflict with the global scope, so we made the skipDefaultLibCheck (and also the skipLibCheck flags) for faster compilations.
We can suggest this flag to users, but the truth is that it's not discoverable. It's also often misused, so I want to stop recommending it to people. 😄
It'd be interesting to see if we can get the same results of skipDefaultLibCheck based on the code users have written. Any program that doesn't contribute a global augmentation, or a declaration in the global scope, doesn't really need to have lib.d.ts checked over again.
@mhegazy and I have discussed this, and it sounds like we have the necessary information after the type-checker undergoes symbol-merging. If no symbols ever get merged outside of lib files, we can make the assumption that lib files never need to get checked. But this requires knowing that all lib files have already had symbols merged up front before any other files the compiler is given.
Pros
- Running with
skipDefaultLibCheckremoves anywhere between 400-700ms on my machine from a "Hello world" file, so we could expect the same here.
Cons
- We'd have to be careful about our assumptions with this flag.
- Users who edit
lib.d.tswouldn't see erroneous changes in a compiler (so we'd likely need aforceDefaultLibCheck). - Ideally, in the absence of edited
lib.d.tsfiles, only our team ever needs to runforceDefaultLibCheck, reducing the cost for all other TypeScript users.
V8 Snapshots
~3 years ago, the V8 team introduced custom startup snapshots. In that post
Limitations aside, startup snapshots remain a great way to save time on initialization. We can shave off 100ms from the startup spent on loading the TypeScript compiler in our example above (on a regular desktop computer). We're looking forward to seeing how you might put custom snapshots to use!
Obviously my machine's not the same as that aforementioned desktop, but I'm getting just a bit over 200ms for running tsc -v, so we could possibly minimize a decent chunk of our raw startup cost. Maybe @hashseed or @bmeurer would be able to lend some insight for how difficult this would be.
Minification
@RyanCavanaugh and I tried some offhand loading benchmarks with Uglify and managed
- to reduce
typescript.js's size by about half - to reduce import time by about 30ms
I don't know how impactful 30ms is, but the size reduction sounds appealing.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files or tests are named. Start by profiling cold compiler startup and the default library-checking path, then investigate the proposed V8 snapshot and minification approaches. Done would require a measured cold-start improvement without compromising compiler correctness, including clear handling for edited lib.d.ts files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100