(perf) implement project version for typescript language service #1236
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the project version, typescript language service would skip rebuilding program when the version is the same.
https://github.com/microsoft/TypeScript/blob/3ef3cdddb338b8f0e6a2c5971d255390b68654ac/src/services/services.ts#L1290
Even though in most cases the rebuild doesn't affect performance very much because most of the state is reused. But update import would be drastically impacted by this. As in its deep call hierarchy, it would try to check if the program object is up-to-date multiple times. So this small difference cumulated to be a big time.
This mostly benefits update import and svelte-check. One of my projects improved check time from 30 seconds to 19 seconds. The same project previously can't even finish update import within 5 minutes. And it's now gone down to less than 1 minute.
One other thing I want to discuss. I also found that if I remove the custom
readFileimplement withgetSnapshotthe updated import of the previously mention project even went down to less than 5 seconds. From what I found, the reason is that typescript usesreadFileto read some source map files (.map) and their source file. There's a certain node module ship declaration files with sourcemap comment and thesrcfolder for some reason. BecausegetSnapshotadd files to the compilation list. It would cause typescript to constantly rebuild the program during update import. Wondering what should we do about this. Should we remove the customreadFileimplementation? Or we can replace it with another way to cache the read file result?