Skip to content

perf(@angular/build): wire module resolution and package.json caches in Angular host - #34439

Closed
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf/library-angular-host-caches
Closed

alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf/library-angular-host-caches

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Always wire host.resolveModuleNameLiterals with resolutionCache and packageJsonCache: Previously, module resolution was only wired on host inside if (hostOptions.fileReplacements). When fileReplacements was undefined (as in @angular/build:library and most application builds), NgCompilerHost.wrap fell back to its own internal ts.createModuleResolutionCache without packageJsonCache, leaving host.getModuleResolutionCache() empty and packageJsonCache unused across watch rebuilds and .d.ts module specifier generation. Using resolveModuleNameLiterals also replaces the deprecated resolveModuleNames hook and passes containingSourceFile.impliedNodeFormat.
  • Break previousProgram retention chain in ensureSourceFileVersions: Compute any missing ts.SourceFile.version fields upfront during ensureSourceFileVersions instead of wrapping program.getSourceFiles in a closure that retains previousProgram across watch rebuilds.

Benchmark

Metric main Branch Delta
Runs (ms) 11644, 12025, 11717, 11823, 11719 11679, 11918, 11640, 11729, 11734
Median (ms) 11719 ms 11729 ms 0.09%
Mean (ms) 11786 ms 11740 ms -0.39%
Min (ms) 11644 ms 11640 ms -0.03%

…in Angular host

- Always wire `host.resolveModuleNameLiterals` using `resolutionCache` (backed by `packageJsonCache`) so `NgCompilerHost.wrap` delegates to it rather than creating an uncached internal `ModuleResolutionCache` without `packageJsonCache`.
- Compute missing `ts.SourceFile` versions upfront in `ensureSourceFileVersions` instead of wrapping `program.getSourceFiles` in a closure that retains `previousProgram` across watch rebuilds.
@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: @angular/build area: performance Issues related to performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant