Skip to content

refactor(@angular/build): centralize sourcemap buffer slicing and removal - #33832

Merged
clydin merged 1 commit into
angular:mainfrom
clydin:perf/sourcemap-buffer-slicing
Aug 11, 2026
Merged

refactor(@angular/build): centralize sourcemap buffer slicing and removal#33832
clydin merged 1 commit into
angular:mainfrom
clydin:perf/sourcemap-buffer-slicing

Conversation

@clydin

@clydin clydin commented Aug 11, 2026

Copy link
Copy Markdown
Member

Extract and centralize trailing sourcemap comment inspection, extraction, and buffer slicing into the shared source-map utility module. Previously, buffer scanning and removal logic was duplicated between the main-thread transformer fast path and the worker script.

The removeSourceMappingURL function is overloaded to accept both string and Uint8Array / Buffer inputs natively. When given raw byte buffers, it uses a zero-copy fast path to strip single trailing sourcemap comments directly from the buffer without decoding into a JavaScript string, falling back to the state-machine parser only when multiple or non-trailing comments are present.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Aug 11, 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 sourcemap comment extraction and removal by introducing a helper function, findTrailingSourceMapComment, which optimizes performance by inspecting trailing byte sequences of raw buffers to slice them directly without full string decoding. This helper is integrated into the JavaScript transformer and worker, and corresponding unit tests are added. The review feedback suggests two key improvements: first, optimizing findTrailingSourceMapComment to avoid decoding the remaining buffer into a UTF-8 string unnecessarily when a non-trailing comment is found early in a large file; second, simplifying the logic in javascript-transformer.ts by handling the string type check upfront to avoid redundant checks.

Comment thread packages/angular/build/src/utils/source-map.ts
Comment thread packages/angular/build/src/tools/esbuild/javascript-transformer.ts Outdated
…oval

Extract and centralize trailing sourcemap comment inspection, extraction, and buffer slicing into the shared source-map utility module. Previously, buffer scanning and removal logic was duplicated between the main-thread transformer fast path and the worker script.

The `removeSourceMappingURL` function is overloaded to accept both `string` and `Uint8Array` / `Buffer` inputs natively. When given raw byte buffers, it uses a zero-copy fast path to strip single trailing sourcemap comments directly from the buffer without decoding into a JavaScript string, falling back to the state-machine parser only when multiple or non-trailing comments are present.
@clydin
clydin force-pushed the perf/sourcemap-buffer-slicing branch from d51b258 to 378fcde Compare August 11, 2026 14:31
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 11, 2026
@clydin
clydin requested a review from alan-agius4 August 11, 2026 14:41
@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 11, 2026
@clydin
clydin merged commit 6a21ad6 into angular:main Aug 11, 2026
41 checks passed
@clydin

clydin commented Aug 11, 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 perf/sourcemap-buffer-slicing branch August 11, 2026 15:18
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