Skip to content

perf(@angular/build): avoid TS AST eviction and d.ts re-emit on external resource edits - #34433

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:perf/library-external-resource-fast-path
Oct 21, 2026
Merged

alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:perf/library-external-resource-fast-path

Conversation

@alan-agius4

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

Copy link
Copy Markdown
Collaborator

This PR implements two watch-mode incremental build optimizations for external Angular component resources (templateUrl and styleUrl):

  1. Register external stylesheet dependencies on stylesheetFile ?? containingFile:
    Previously, transformStylesheet in the library builder registered result.referencedFiles directly against containingFile (the component .ts file). Editing an external stylesheet or an imported SCSS partial therefore added the component .ts file to effectiveModifiedFiles, evicting the .ts file from TypeScriptCompilation's AST cache and forcing TypeScript to re-read and re-parse the .ts file on disk. By registering external stylesheet references on stylesheetFile ?? containingFile, expandModifiedFiles expands an edited _partial.scss to comp.scss, which getResourceDependencies then maps to comp.ts via resourceModifiedFiles without evicting the cached ts.SourceFile AST.

  2. Skip .d.ts re-emit (EmitOnly.Js) for unchanged ts.SourceFiles on resource-only edits:
    Persists a WeakSet<ts.SourceFile> (emittedDtsSourceFiles) on AngularCompilationState across incremental watch builds. When a component's ts.SourceFile object is unchanged in memory (i.e. only its external .html template or .scss/.css stylesheet was modified), the fallback emit loop passes EmitOnly.Js to program.emit(), skipping redundant .d.ts generation and downstream declaration bundling/processing.

@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Oct 20, 2026
@alan-agius4
alan-agius4 requested a review from dgp1130 October 20, 2026 10:25
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Oct 20, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review October 20, 2026 15:21

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the file reference tracking in the library builder compilation pipeline and improves AOT compilation state persistence by tracking emitted d.ts source files in a WeakSet across compilations instead of using a local Set. Additionally, a new integration test has been added to verify rebuilding behavior and recovery from template errors when external Sass partials or templates are modified. I have no feedback to provide as there are no review comments.

@alan-agius4
alan-agius4 force-pushed the perf/library-external-resource-fast-path branch from caadb0e to ee01c14 Compare October 20, 2026 16:37
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 21, 2026
…nal resource edits

Register external stylesheet dependencies on `stylesheetFile ?? containingFile` in the library builder so modifying an external stylesheet or imported SCSS partial does not add the component `.ts` file to `effectiveModifiedFiles` and evict it from `TypeScriptCompilation`'s AST cache. Instead, `getResourceDependencies` maps the modified stylesheet back to the component `.ts` file via `resourceModifiedFiles` while reusing the cached `ts.SourceFile` AST.

Additionally, persist a `WeakSet<ts.SourceFile>` of emitted declaration files on `AngularCompilationState` across incremental watch builds so that unchanged `ts.SourceFile`s re-emitted solely due to external resource edits (`templateUrl` / `styleUrl`) pass `EmitOnly.Js` to `program.emit`, skipping redundant `.d.ts` generation and downstream declaration processing.
@alan-agius4
alan-agius4 force-pushed the perf/library-external-resource-fast-path branch from ee01c14 to 95c28b8 Compare October 21, 2026 06:28
@alan-agius4
alan-agius4 merged commit 6bae97b into angular:main Oct 21, 2026
15 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

@alan-agius4
alan-agius4 deleted the perf/library-external-resource-fast-path branch October 21, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build area: performance Issues related to performance target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants