Skip to content

refactor(@angular/build): bypass worker dispatch for untransformed files in JS transformer - #33797

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/optimize-transformer-fast-path
Open

refactor(@angular/build): bypass worker dispatch for untransformed files in JS transformer#33797
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/optimize-transformer-fast-path

Conversation

@clydin

@clydin clydin commented Aug 6, 2026

Copy link
Copy Markdown
Member

Make transformData symmetrical to accept both string and Uint8Array inputs, allowing transformFile to directly delegate to transformData after reading from disk or cache. When no transformations are required, untransformed files bypass worker pool dispatch, thread synchronization, and string decoding overhead. In addition, introduce a fast byte-level check on raw ASCII bytes using a pre-allocated comment buffer to immediately return untouched buffers when no sourcemap comment exists.

@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 JavaScriptTransformer to support Uint8Array inputs, optimizing performance by avoiding UTF-8 decoding when no sourcemap comments are present and transferring standalone ArrayBuffers to worker threads. However, removing the throttle wrapper from the file transformation method can lead to EMFILE errors and memory exhaustion due to concurrent file reads. To address this, the throttle should be kept at the file-reading level and removed from the worker pool dispatch to prevent deadlocks. Additionally, the sourcemap comment detection should be made more robust by searching for sourceMappingURL= to capture legacy and block comment formats.

Comment thread packages/angular/build/src/tools/esbuild/javascript-transformer.ts
Comment thread packages/angular/build/src/tools/esbuild/javascript-transformer.ts Outdated
Comment thread packages/angular/build/src/tools/esbuild/javascript-transformer.ts Outdated
…les in JS transformer

Make transformData symmetrical to accept both string and Uint8Array inputs, allowing transformFile to directly delegate to transformData after reading from disk or cache. When no transformations are required, untransformed files bypass worker pool dispatch, thread synchronization, and string decoding overhead. In addition, introduce a fast byte-level check on raw ASCII bytes using a pre-allocated comment buffer to immediately return untouched buffers when no sourcemap comment exists.
@clydin
clydin force-pushed the perf/optimize-transformer-fast-path branch from 2e7a666 to 9f90003 Compare August 6, 2026 15:42
@clydin clydin added target: minor This PR is targeted for the next minor release action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 6, 2026
@clydin
clydin requested a review from alan-agius4 August 6, 2026 18:28
@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 Aug 6, 2026
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