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
tsc
tried to check thattslib
file exists almost 3k times).Quite possibly that such behavior is related to set
baseUrl
compiler 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-folder
folder,baseUrl
option is set to./src
,importHelpers
option is enabled, and the file needs to import helpers fromtslib
.In our case we get the next requests in
tryFile
function:This requests are made before
tslib
is resolved from/project/node_modules
folder.tsc
makes at least 14 extra syscalls. But yeah, we can have localtslib
and then resolving will stop.The same resolving will be performed for all other files from
/project/src/sub-folder
folder.Perhaps this example is related to
tslib
only, 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
master
branch yet due #26978, but I believe the differences will be very similar)typescript@3.0.1 (from npm):
release-3.0 branch with applied fixes:
Difference:
I believe that here only
Program time
andTotal time
are valuable.I hope this fix can help someone improve its build speed.
Open questions:
createCompilerHost
function instead? If so, what aboutcreateSolutionBuilderHost
intsbuild.ts
- it seems that it usescreateCompilerHost
as host for watch mode?createWatchCompilerHost
? It is possible that we can use caches while compilation and clear it right before compilation start.