-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added caches to tsc's CompilerHost #27068
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want this in compiler host. Just like #26259 the user of createProgram can always cache the results it wants. Eg. You can move this to tsLoader to cache this instead of of affecting usage of tsc
Now it is in tsc (not in the compiler host), is it ok?
I totally agree with it. I guess that
But what if we want to compile via cli |
@sheetalkamat you marked this PR as "requested changes", but can you please say what kind of changed I need to do? Or it means that this PR never will be merged? |
@RyanCavanaugh @DanielRosenwasser anybody? 🙁 |
@RyanCavanaugh Any updates? |
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.