perf(ivy): use module resolution cache (#34332)
During TypeScript module resolution, a lot of filesystem requests are done. This is quite an expensive operation, so a module resolution cache can be used to speed up the process significantly. This commit lets the Ivy compiler perform all module resolution with a module resolution cache. Note that the module resolution behavior can be changed with a custom compiler host, in which case that custom host implementation is responsible for caching. In the case of the Angular CLI a custom compiler host with proper module resolution caching is already in place, so the CLI already has this optimization. PR Close #34332
This commit is contained in:
@ -177,7 +177,10 @@ export class NgtscProgram implements api.Program {
|
||||
this.reuseTsProgram = this.tsProgram;
|
||||
|
||||
this.entryPoint = entryPoint !== null ? getSourceFileOrNull(this.tsProgram, entryPoint) : null;
|
||||
this.moduleResolver = new ModuleResolver(this.tsProgram, options, this.host);
|
||||
const moduleResolutionCache = ts.createModuleResolutionCache(
|
||||
this.host.getCurrentDirectory(), fileName => this.host.getCanonicalFileName(fileName));
|
||||
this.moduleResolver =
|
||||
new ModuleResolver(this.tsProgram, options, this.host, moduleResolutionCache);
|
||||
this.cycleAnalyzer = new CycleAnalyzer(new ImportGraph(this.moduleResolver));
|
||||
this.defaultImportTracker = new DefaultImportTracker();
|
||||
if (oldProgram === undefined) {
|
||||
@ -287,7 +290,8 @@ export class NgtscProgram implements api.Program {
|
||||
// of the root files.
|
||||
const containingFile = this.tsProgram.getRootFileNames()[0];
|
||||
const [entryPath, moduleName] = entryRoute.split('#');
|
||||
const resolvedModule = resolveModuleName(entryPath, containingFile, this.options, this.host);
|
||||
const resolvedModule =
|
||||
resolveModuleName(entryPath, containingFile, this.options, this.host, null);
|
||||
|
||||
if (resolvedModule) {
|
||||
entryRoute = entryPointKeyFor(resolvedModule.resolvedFileName, moduleName);
|
||||
@ -587,8 +591,7 @@ export class NgtscProgram implements api.Program {
|
||||
// First, try to use local identifiers if available.
|
||||
new LocalIdentifierStrategy(),
|
||||
// Next, attempt to use an absolute import.
|
||||
new AbsoluteModuleStrategy(
|
||||
this.tsProgram, checker, this.options, this.host, this.reflector),
|
||||
new AbsoluteModuleStrategy(this.tsProgram, checker, this.moduleResolver, this.reflector),
|
||||
// Finally, check if the reference is being written into a file within the project's .ts
|
||||
// sources, and use a relative import if so. If this fails, ReferenceEmitter will throw
|
||||
// an error.
|
||||
|
Reference in New Issue
Block a user