Skip to content

perf(@angular/build): implement sliding-window batching and worker translation eviction - #33913

Open
clydin wants to merge 3 commits into
angular:mainfrom
clydin:perf/i18n-inliner-sliding-window-eviction
Open

perf(@angular/build): implement sliding-window batching and worker translation eviction#33913
clydin wants to merge 3 commits into
angular:mainfrom
clydin:perf/i18n-inliner-sliding-window-eviction

Conversation

@clydin

@clydin clydin commented Aug 24, 2026

Copy link
Copy Markdown
Member

In enterprise Angular applications with a high number of locales (e.g. 20–50+), deserializing translation dictionaries into native JavaScript objects across all worker threads simultaneously can lead to multi-gigabyte resident memory footprints in V8 worker heaps.

This change introduces sliding-window locale batching and lock-free translation eviction:

  • I18nInliner.inlineAll processes locales in sliding windows of up to 8 locales each (DEFAULT_LOCALE_WINDOW_SIZE), capping peak memory while retaining maximum multi-locale batching throughput.
  • Worker tasks receive an activeLocales array on each batch request. Workers automatically purge any cached translation dictionaries in deserializedTranslations that are not part of the active window when transitioning across window boundaries.

…-batch inlining

When processing files where all remaining locales fit into a single batch, the file will only be transformed once across all worker threads. Retaining the parsed AST and source code in the worker's long-term `fileDataCache` leads to monotonic memory growth across multi-file builds without providing any cache reuse.

This change marks single-batch requests as `ephemeral`, allowing the worker to extract localization metadata and perform inlining within the execution frame without caching the file data long-term. The parsed AST and code are then naturally garbage-collected when the batch action completes.
@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Aug 24, 2026
@clydin clydin added the target: minor This PR is targeted for the next minor release label Aug 24, 2026
@clydin
clydin marked this pull request as ready for review August 24, 2026 21:15

@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 sliding window mechanism to process locales in batches, capping peak worker memory, and adds an ephemeral flag to avoid caching file data long-term in the worker. The reviewer identified a significant CPU performance regression caused by the ephemeral flag when the number of locales exceeds the window size, as it forces the worker to repeatedly re-load and re-parse the same files. The reviewer recommends removing the ephemeral flag entirely and always caching the file data in the worker.

Comment thread packages/angular/build/src/tools/esbuild/i18n-inliner.ts Outdated
Comment thread packages/angular/build/src/tools/esbuild/i18n-inliner.ts
Comment thread packages/angular/build/src/tools/esbuild/i18n-inliner-worker.ts
Comment thread packages/angular/build/src/tools/esbuild/i18n-inliner-worker.ts
…anslation eviction

In enterprise Angular applications with a high number of locales (e.g. 20–50+), deserializing translation dictionaries into native JavaScript objects across all worker threads simultaneously can lead to multi-gigabyte resident memory footprints in V8 worker heaps.

This change introduces sliding-window locale batching and lock-free translation eviction:
- `I18nInliner.inlineAll` processes locales in sliding windows of up to 8 locales each (`DEFAULT_LOCALE_WINDOW_SIZE`), capping peak memory while retaining maximum multi-locale batching throughput.
- Worker tasks receive an `activeLocales` array on each batch request. Workers automatically purge any cached translation dictionaries in `deserializedTranslations` that are not part of the active window when transitioning across window boundaries.
@clydin
clydin force-pushed the perf/i18n-inliner-sliding-window-eviction branch from 379a108 to 625ee76 Compare August 24, 2026 21:42
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 24, 2026
…liner

Updates I18nInliner to instantiate and use a namespaced Cache<TransformedFileResult> instance (cacheStore.createCache('transforms')) instead of directly invoking lower-level CacheStore methods (get/set).

Using the Cache abstraction ensures standard namespace partitioning within the angular-i18n persistent cache store, automatic in-flight promise management, and proper get/put promise semantics.
@clydin
clydin requested a review from alan-agius4 August 24, 2026 23:17
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