Added caches to tsc's CompilerHost #27068
Closed
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.
Related issues: #26871, TypeStrong/ts-loader#825.
After debugging the compiler I have been noticed that some functions are called multiple times with the same arguments (for example, in our project
tsctried to check thattslibfile exists almost 3k times).Quite possibly that such behavior is related to set
baseUrlcompiler option.For example, I have observe the following situation in our project (I don't understand what exactly affects on this):
Let's say that some file is placed
/project/src/sub-folderfolder,baseUrloption is set to./src,importHelpersoption is enabled, and the file needs to import helpers fromtslib.In our case we get the next requests in
tryFilefunction:This requests are made before
tslibis resolved from/project/node_modulesfolder.tscmakes at least 14 extra syscalls. But yeah, we can have localtsliband then resolving will stop.The same resolving will be performed for all other files from
/project/src/sub-folderfolder.Perhaps this example is related to
tslibonly, and for other imported modules the compiler makes less requests.This PR adds caches for some CompilerHost's functions while compiling via
tsc.Below are some diagnostics for our project (average of 3 runs).
(our project is not compiled with
masterbranch yet due #26978, but I believe the differences will be very similar)[email protected] (from npm):
release-3.0 branch with applied fixes:
Difference:
I believe that here only
Program timeandTotal timeare valuable.I hope this fix can help someone improve its build speed.
Open questions:
createCompilerHostfunction instead? If so, what aboutcreateSolutionBuilderHostintsbuild.ts- it seems that it usescreateCompilerHostas host for watch mode?createWatchCompilerHost? It is possible that we can use caches while compilation and clear it right before compilation start.