Skip to content

refactor(@angular/build): remove arbitrary cap from maxWorkers and localize bundling concurrency - #33994

Merged
clydin merged 1 commit into
angular:mainfrom
clydin:refactor/decouple-max-workers
Sep 2, 2026
Merged

refactor(@angular/build): remove arbitrary cap from maxWorkers and localize bundling concurrency#33994
clydin merged 1 commit into
angular:mainfrom
clydin:refactor/decouple-max-workers

Conversation

@clydin

@clydin clydin commented Sep 2, 2026

Copy link
Copy Markdown
Member

Previously, maxWorkers was clamped to a maximum of 4 globally across the entire build system. This limitation was originally introduced to mitigate memory pressure from Babel transforms, but subsequent optimizations such as the OXC linker migration, zero-copy shared memory for i18n translations, and bounded memory buffers have eliminated those memory constraints. Consequently, clamping maxWorkers artificially restricted post-bundle operations like translation inlining and route prerendering on high-core systems.

This change decouples the global default of maxWorkers so that it scales with available parallelism minus one, ensuring the main thread is not starved while allowing parallel tasks to utilize full hardware capacity. When NG_BUILD_MAX_WORKERS is specified, it is safely parsed as a positive integer or falls back to the default available parallelism.

To avoid CPU contention during bundling when esbuild concurrently executes its internal multi-threaded Go routine across all cores, transformation concurrency for JavaScriptTransformer is now locally capped to at most 4 unless NG_BUILD_MAX_WORKERS has been explicitly provided, tracked via the exported hasCustomMaxWorkers option.

…calize bundling concurrency

Previously, maxWorkers was clamped to a maximum of 4 globally across the entire build system. This limitation was originally introduced to mitigate memory pressure from Babel transforms, but subsequent optimizations such as the OXC linker migration, zero-copy shared memory for i18n translations, and bounded memory buffers have eliminated those memory constraints. Consequently, clamping maxWorkers artificially restricted post-bundle operations like translation inlining and route prerendering on high-core systems.

This change decouples the global default of maxWorkers so that it scales with available parallelism minus one, ensuring the main thread is not starved while allowing parallel tasks to utilize full hardware capacity. When NG_BUILD_MAX_WORKERS is specified, it is safely parsed as a positive integer or falls back to the default available parallelism.

To avoid CPU contention during bundling when esbuild concurrently executes its internal multi-threaded Go routine across all cores, transformation concurrency for JavaScriptTransformer is now locally capped to at most 4 unless NG_BUILD_MAX_WORKERS has been explicitly provided, tracked via the exported hasCustomMaxWorkers option.
@clydin clydin added the target: minor This PR is targeted for the next minor release label Sep 2, 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 configuration of the maximum number of workers via the NG_BUILD_MAX_WORKERS environment variable. It introduces hasCustomMaxWorkers to identify if a custom worker count was explicitly set. The default worker count now defaults to available parallelism minus one, while the compiler plugin caps transformation concurrency to 4 by default to avoid CPU contention during bundling. Comprehensive unit tests have been added to verify the environment variable parsing. There are no review comments, so I have no feedback to provide.

@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 2, 2026
@clydin
clydin requested a review from alan-agius4 September 2, 2026 17:39
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 2, 2026
@clydin
clydin merged commit c05a270 into angular:main Sep 2, 2026
43 checks passed
@clydin

clydin commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

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

@clydin
clydin deleted the refactor/decouple-max-workers branch September 2, 2026 17:51
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 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