Skip to content

perf(@angular/build): decouple diagnostic type checking from build start - #34043

Open
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf/decouple-compiler-diagnostics
Open

perf(@angular/build): decouple diagnostic type checking from build start#34043
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf/decouple-compiler-diagnostics

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

Previously, the compiler plugin sequentially awaited compilation.diagnoseFiles() in build.onStart before returning to esbuild.

Because build.onStart blocked until TypeScript diagnostic checks finished, esbuild's Go bundler sat idle while single-threaded type checking occurred, preventing module resolution and bundling from running concurrently.

To overlap bundling with type checking:

  • Initiate compilation.diagnoseFiles() asynchronously during build.onStart without awaiting its completion.
  • Allow build.onStart to return immediately once compilation emit is complete, enabling esbuild to begin bundling and file resolution concurrently.
  • Await the diagnostics promise in build.onEnd, merging any diagnostic errors or warnings into the final build result.

In benchmarks on clean builds, this overlaps diagnostic checks with bundling, saving ~150 ms in small projects and 500 ms to 2,000+ ms in large enterprise codebases.

@alan-agius4 alan-agius4 added the target: minor This PR is targeted for the next minor release label Sep 8, 2026
@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Sep 8, 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 defers the resolution of Angular compilation diagnostics by storing the diagnosticsPromise during the start phase and awaiting it asynchronously inside the build.onEnd callback. Feedback on these changes highlights two issues: first, a potential unhandledRejection in Node.js if compilation.diagnoseFiles rejects before onEnd is called, which can be mitigated by attaching a .catch() handler immediately; second, in watch mode, hasCompilationErrors is not reset to true at the start of a rebuild, which can incorrectly signal to other compilations that there are no errors if a rebuild fails early.

Comment thread packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts Outdated
Comment thread packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts
Previously, the compiler plugin sequentially awaited compilation.diagnoseFiles() in build.onStart before returning to esbuild.

Because build.onStart blocked until TypeScript diagnostic checks finished, esbuild's Go bundler sat idle while single-threaded type checking occurred, preventing module resolution and bundling from running concurrently.

To overlap bundling with type checking:
- Initiate compilation.diagnoseFiles() asynchronously during build.onStart without awaiting its completion.
- Allow build.onStart to return immediately once compilation emit is complete, enabling esbuild to begin bundling and file resolution concurrently.
- Await the diagnostics promise in build.onEnd, merging any diagnostic errors or warnings into the final build result.

In benchmarks on clean builds, this overlaps diagnostic checks with bundling, saving ~150 ms in small projects and 500 ms to 2,000+ ms in large enterprise codebases.
@alan-agius4
alan-agius4 force-pushed the perf/decouple-compiler-diagnostics branch from d31ff5e to b45232d Compare September 8, 2026 13:25
@alan-agius4
alan-agius4 requested a review from clydin September 8, 2026 14:57
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 8, 2026
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.

1 participant