refactor(@angular/build): centralize sourcemap buffer slicing and removal - #33832
Conversation
There was a problem hiding this comment.
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.
…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.
d51b258 to
378fcde
Compare
|
This PR was merged into the repository. The changes were merged into the following branches:
|
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
removeSourceMappingURLfunction is overloaded to accept bothstringandUint8Array/Bufferinputs 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.