Skip to content

refactor(@angular/build): bypass worker dispatch for non-Angular files with byte-level linker pre-check - #33825

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/linker-byte-precheck
Open

refactor(@angular/build): bypass worker dispatch for non-Angular files with byte-level linker pre-check#33825
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/linker-byte-precheck

Conversation

@clydin

@clydin clydin commented Aug 10, 2026

Copy link
Copy Markdown
Member

In AOT compilation mode, JavaScript files loaded from node_modules are processed with skipLinker: false. Previously, requiresLinking was only evaluated inside worker threads after string decoding, forcing every 3rd-party dependency to be dispatched to the Piscina worker pool even when no linking or transformations were needed (such as during development server runs).

This commit introduces a fast byte-level pre-check for the Angular partial declaration prefix (ɵɵngDeclare) directly in JavaScriptTransformer.transformData on the main thread. By scanning incoming raw buffers with Buffer.indexOf before thread dispatch, files that do not require linking (and have no advanced optimizations or coverage enabled) can bypass worker thread scheduling, message serialization, and string decoding entirely.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Aug 10, 2026
@clydin
clydin marked this pull request as ready for review August 10, 2026 19:17

@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 optimizes the JavaScript transformation process by moving the requiresLinking check from the worker thread to the main thread, allowing the build to bypass worker communication overhead when linking is not required. Feedback is provided regarding a potential issue in the regular expression used to exclude certain paths (like @angular/core and @angular/compiler), where the low precedence of the alternation operator could cause false positives on packages like @angular/compiler-cli.

Comment thread packages/angular/build/src/tools/esbuild/javascript-transformer.ts Outdated
…s with byte-level linker pre-check

In AOT compilation mode, JavaScript files loaded from node_modules are processed with `skipLinker: false`. Previously, `requiresLinking` was only evaluated inside worker threads after string decoding, forcing every 3rd-party dependency to be dispatched to the Piscina worker pool even when no linking or transformations were needed (such as during development server runs).

This commit introduces a fast byte-level pre-check for the Angular partial declaration prefix (`ɵɵngDeclare`) directly in `JavaScriptTransformer.transformData` on the main thread. By scanning incoming raw buffers with `Buffer.indexOf` before thread dispatch, files that do not require linking (and have no advanced optimizations or coverage enabled) can bypass worker thread scheduling, message serialization, and string decoding entirely.
@clydin
clydin force-pushed the perf/linker-byte-precheck branch from b1ff4b6 to c943b89 Compare August 10, 2026 19:27
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 10, 2026
@clydin
clydin requested a review from alan-agius4 August 10, 2026 20:03
? data
: Buffer.from(data.buffer, data.byteOffset, data.byteLength);

return dataBuffer.indexOf(LINKER_DECLARATION_PREFIX_BYTES) !== -1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

Suggested change
return dataBuffer.indexOf(LINKER_DECLARATION_PREFIX_BYTES) !== -1;
return dataBuffer.includes(LINKER_DECLARATION_PREFIX_BYTES);

@alan-agius4 alan-agius4 removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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