Skip to content

perf(@angular/build): optimize incremental watch rebuilds in AOT compilation - #34173

Open
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf/angular-compilation-watch
Open

alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf/angular-compilation-watch

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Optimizes incremental watch rebuilds in AotCompilation:

  • Pre-populate .d.ts shape signatures on the previous BuilderProgram for modified files prior to diffing when type-checking or TypeScript transpilation is active, preventing false-positive .d.ts cascades on incremental watch edits.
  • Synchronize typeScriptProgram with Angular's template type-checking program (angularCompiler.getCurrentProgram()) after collectDiagnostics() and clear uncommitted changedFilesSet and oldSignatures entries so subsequent incremental builds preserve .d.ts signatures and do not treat .ngtypecheck.ts shims as newly added files.
  • Detect affected dependent .ngtypecheck.ts shims in isolatedModules / verbatimModuleSyntax mode via TypeScript's state.hasCalledUpdateShapeSignature, ensuring cross-component template diagnostics are re-evaluated when a dependency's .d.ts shape changes without cascading on private edits.
  • Avoid filter().flatMap() allocations and skip getResourceDependencies() for declaration files when collecting referencedFiles.

Tip

Consider enabling Hide whitespace (view with ?w=1) when reviewing this PR for a cleaner diff.

@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Sep 25, 2026

@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 optimizes incremental builds in the Angular compilation pipeline by caching the tsconfig configuration and managing the internal state of the TypeScript BuilderProgram to prevent false-positive .d.ts cascades during watch rebuilds. It also refactors file reference collection to be more efficient. The feedback highlights a critical issue where the newly added builder program synchronization and state-committing logic is placed at the end of a generator function. Since generator execution can terminate early, this logic should be wrapped in a try...finally block to guarantee it runs.

Comment thread packages/angular/build/src/tools/angular/compilation/aot-compilation.ts Outdated
@alan-agius4
alan-agius4 marked this pull request as draft September 25, 2026 08:08
@alan-agius4 alan-agius4 added the target: minor This PR is targeted for the next minor release label Sep 25, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review September 25, 2026 08:13

@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 optimizes incremental builds in the Angular compilation pipeline by caching the parsed TypeScript configuration and introducing state synchronization to prevent false-positive .d.ts cascades. It also refactors resource dependency handling during file reference collection. The review feedback suggests making the .json file extension check case-insensitive to ensure robust cache invalidation across different filesystems.

Comment thread packages/angular/build/src/tools/angular/compilation/typescript-compilation.ts Outdated
@alan-agius4
alan-agius4 force-pushed the perf/angular-compilation-watch branch 2 times, most recently from ad232b6 to c3b5d77 Compare September 25, 2026 08:17
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 25, 2026
@alan-agius4
alan-agius4 requested a review from clydin September 25, 2026 08:25
@thekhegay

This comment was marked as outdated.

@alan-agius4
alan-agius4 force-pushed the perf/angular-compilation-watch branch 4 times, most recently from 0912b99 to f23c21c Compare September 28, 2026 17:31
@alan-agius4 alan-agius4 changed the title perf(@angular/build): optimize incremental watch rebuilds in angular compilation perf(@angular/build): optimize incremental watch rebuilds in AOT compilation Sep 28, 2026
@alan-agius4
alan-agius4 force-pushed the perf/angular-compilation-watch branch from f23c21c to 357186d Compare October 1, 2026 09:44
…ilation

- Pre-populate `.d.ts` shape signatures on the previous `BuilderProgram` for modified files prior to diffing when type-checking or TypeScript transpilation is active, preventing false-positive `.d.ts` cascades on incremental watch edits.
- Synchronize `typeScriptProgram` with `angularCompiler.getCurrentProgram()` after `collectDiagnostics()` and clear uncommitted `changedFilesSet` and `oldSignatures` entries so subsequent incremental builds preserve `.d.ts` signatures and do not treat `.ngtypecheck.ts` shims as newly added files.
- Detect affected dependent `.ngtypecheck.ts` shims in `isolatedModules` / `verbatimModuleSyntax` mode via TypeScript's `state.hasCalledUpdateShapeSignature`, ensuring cross-component template diagnostics are re-evaluated when a dependency's `.d.ts` shape changes without cascading on private edits.
- Avoid `filter().flatMap()` allocations and skip `getResourceDependencies()` for declaration files when collecting `referencedFiles`.
@alan-agius4
alan-agius4 force-pushed the perf/angular-compilation-watch branch from 357186d to 8e343ea Compare October 2, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer 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