Skip to content

perf(@angular/build): reduce watcher debounce latency for faster incremental rebuilds - #34048

Open
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf/watcher-debounce-tuning
Open

perf(@angular/build): reduce watcher debounce latency for faster incremental rebuilds#34048
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf/watcher-debounce-tuning

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Previously, the esbuild file watcher utilized a static 250 ms trailing debounce timer (scheduleFlush) after each filesystem change event.

In incremental watch mode rebuilds where the actual compile and bundle step takes 150 ms to 220 ms, this 250 ms debounce delay accounted for over 50% of the developer-perceived turnaround time.

To accelerate the developer edit-refresh feedback loop:

  • Replace the fixed 250 ms debounce in WatcherQueue with an adaptive debounce mechanism.
  • Use a 100 ms debounce delay to reliably coalesce rapid multi-file atomic saves and editor formatters while reducing debounce latency by 60% (150 ms faster).
  • Introduce a 250 ms maximum wait ceiling (maxWaitMs) to ensure rebuilds are not postponed indefinitely during continuous file events.

In benchmarks on ng build --watch, single-file save turnaround dropped from 470–550 ms to ~250–320 ms (~45% reduction in latency), saving approximately 150 ms per save.

@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Sep 9, 2026
@alan-agius4
alan-agius4 force-pushed the perf/watcher-debounce-tuning branch from ef27fe2 to 59aea7b Compare September 9, 2026 07:26
@alan-agius4
alan-agius4 requested a review from clydin September 9, 2026 08:21
@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 Sep 9, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review September 9, 2026 08: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 introduces a debouncing mechanism with a maximum wait time to the WatcherQueue class, ensuring that file changes are flushed within a specified timeframe. The review feedback highlights two valuable improvement opportunities: using a local variable to maintain TypeScript type narrowing for firstChangeTime across external function calls, and removing a redundant reset of firstChangeTime inside the setTimeout callback since it is already handled in the flush method.

Comment thread packages/angular/build/src/tools/esbuild/watcher.ts Outdated
Comment thread packages/angular/build/src/tools/esbuild/watcher.ts
…emental rebuilds

Previously, the esbuild file watcher utilized a static 250 ms trailing debounce timer (scheduleFlush) after each filesystem change event.

In incremental watch mode rebuilds where the actual compile and bundle step takes 150 ms to 220 ms, this 250 ms debounce delay accounted for over 50% of the developer-perceived turnaround time.

To accelerate the developer edit-refresh feedback loop:
- Replace the fixed 250 ms debounce in WatcherQueue with an adaptive debounce mechanism.
- Use a 100 ms debounce delay to reliably coalesce rapid multi-file atomic saves and editor formatters while reducing debounce latency by 60% (150 ms faster).
- Introduce a 250 ms maximum wait ceiling (maxWaitMs) to ensure rebuilds are not postponed indefinitely during continuous file events.

In benchmarks on ng build --watch, single-file save turnaround dropped from 470–550 ms to ~250–320 ms (~45% reduction in latency), saving approximately 150 ms per save.
@alan-agius4
alan-agius4 force-pushed the perf/watcher-debounce-tuning branch from 59aea7b to 50b8f2e Compare September 9, 2026 08:27
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