Skip to content

perf(@angular/build): avoid sharding intermediate files under worker surplus in i18n inliner - #34219

Merged
clydin merged 2 commits into
angular:mainfrom
clydin:perf-inliner-file-surplus-sharding
Oct 1, 2026
Merged

clydin merged 2 commits into
angular:mainfrom
clydin:perf-inliner-file-surplus-sharding

Conversation

@clydin

@clydin clydin commented Sep 30, 2026

Copy link
Copy Markdown
Member

When the number of uncached files in an inlining window meets or exceeds
the worker pool concurrency, the thread pool already has sufficient
file-level parallelism to keep all workers fully utilized.

Previously, all intermediate files (files between 100 KB and 70% of the
maximum file size) were sharded into batches of half their locales
regardless of the total file count. In applications with many chunks,
this doubled the number of worker tasks and forced multiple worker threads
to independently parse the same JavaScript file and decode the same source
map.

Intermediate files are now processed with all window locales in a single
batch whenever the file count is greater than or equal to the worker thread
count. This halves the task count for intermediate chunks, eliminates
redundant AST and sourcemap parsing across threads, and reduces IPC and
scheduling overhead.

…surplus in i18n inliner

When the number of uncached files in an inlining window meets or exceeds
the worker pool concurrency, the thread pool already has sufficient
file-level parallelism to keep all workers fully utilized.

Previously, all intermediate files (files between 100 KB and 70% of the
maximum file size) were sharded into batches of half their locales
regardless of the total file count. In applications with many chunks,
this doubled the number of worker tasks and forced multiple worker threads
to independently parse the same JavaScript file and decode the same source
map.

Intermediate files are now processed with all window locales in a single
batch whenever the file count is greater than or equal to the worker thread
count. This halves the task count for intermediate chunks, eliminates
redundant AST and sourcemap parsing across threads, and reduces IPC and
scheduling overhead.
@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Sep 30, 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 refactors the i18n inliner to optimize worker thread allocation for dominant files by dynamically scaling the maximum dominant workers based on the count of dominant files. It also introduces a check to process intermediate files in a single batch when the worker pool is already saturated, reducing IPC overhead. The review feedback suggests defensively guarding against potential division-by-zero errors when calculating target workers by ensuring the dominant count is at least one.

Comment thread packages/angular/build/src/tools/i18n/i18n-inliner.ts Outdated
…nt files in i18n inliner

Previously, MAX_DOMINANT_WORKERS (4) was applied independently per dominant
file. When multiple large bundles qualified as dominant in the same window
(e.g., 3 bundles of 3 MB each), each bundle claimed up to 4 worker threads,
allocating up to 12 heavy tasks simultaneously. This could saturate the
entire worker pool with large AST and sourcemap remappings, starving
smaller chunks and spiking peak RSS.

The target worker count per dominant file now divides MAX_DOMINANT_WORKERS
by the number of dominant files in the window. This preserves the existing
4-worker allocation when a single dominant file is present, while bounding
aggregate dominant concurrency across the pool when multiple large bundles
exist.
@clydin
clydin force-pushed the perf-inliner-file-surplus-sharding branch from 715ddea to 2afc7f5 Compare October 1, 2026 00:13
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 1, 2026
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release target: patch This PR is targeted for the next patch release and removed 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 1, 2026
@clydin
clydin merged commit 7c1c841 into angular:main Oct 1, 2026
43 checks passed
@clydin

clydin commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

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

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: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants