-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Can Module Resolution Cache Usage Be Improved? #40356
Comments
i have had chat in past about this with @RyanCavanaugh that we could this as part of some option/flag where user opt in to say anything that is already resolved persists across compilations as we had talked about getting this for 4.1. The work to get that involves:
|
Thank you @sheetalkamat and @DanielRosenwasser for looking into this for us. |
Thanks from me as well. Appreciate the quick response yesterday and glad this was already on the radar. |
It sounds like there's a larger scope version of this where resolution cache is persisted to disk between In the meantime I want to drop a quick thought. I think there's a potential short-term, lower payoff alternative without a flag. TypeScript/src/services/documentRegistry.ts Lines 104 to 111 in 7838b01
Although it may not be worth exploring that if the end goal for 4.1.0 is to implement the larger scope, higher payoff version. |
Gave this an attempt and failed on a test that remapped
|
TypeScript Version: 4.1.0-dev.20200902
Search Terms:
Expected behavior:
Module resolution cache for files from a different
Program
is reused byresolveModuleNamesReusingOldState
.Actual behavior:
resolvedModules
is always recalculated when a newProgram
is created.I'm looking at a specific section of
src/compiler/program.ts
and see a place module resolution cache is available but unused. Utilizing this module resolution cache in my project reduced load time from ~18,768ms to ~7774ms in a specific (but common) scenario.Suppose packages
dep
andmain
are loaded one after the other intsserver
, andmain
depends ondep
. In this case:Program
formain
, eventually pulling files fromdep
intomain
’s program.dep
’sSourceFile
lookups,DocumentRegistry
returns entries withfile.resolvedModules
already populated.resolveModuleNamesReusingOldState
ignores this and always recalculatesfile.resolvedModules
when a newProgram
is constructed.I'd like help in determining whether the
resolvedModules
recalculation in (3) is always necessary. Here's the guard in question for reference:TypeScript/src/compiler/program.ts
Lines 1067 to 1075 in 3b502f4
I applied an extremely naive patch to play with:
With this patch and running
tsserver
against an experimental repo, I saw:packages/b/src/b.ts
afterpackages/a/src/a.ts
. From ~8751ms to ~3866ms. (Packagesa
andb
are small but both depend onc
which has 50,000 files.)TypeScript/src/testRunner/compilerRunner.ts
Lines 231 to 238 in 3b502f4
I'd like to provide a pull request but curious for initial thoughts before doing so. It's possible I'm misunderstanding something about module resolution that makes this performance optimization not doable. Is that the case?
Thanks in advance!
The text was updated successfully, but these errors were encountered: