Skip to content

perf(@angular/build): avoid full JSON parsing when updating sourcemap ignore list - #34040

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:perf/sourcemap-ignorelist-splice
Sep 8, 2026
Merged

perf(@angular/build): avoid full JSON parsing when updating sourcemap ignore list#34040
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:perf/sourcemap-ignorelist-splice

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

Previously, the sourcemap ignore-list plugin parsed the entire generated sourcemap buffer into a JavaScript object via JSON.parse and re-serialized it via JSON.stringify to inject x_google_ignoreList.

In typical applications, sourcemap files range from 2 MB to 10 MB+ each. The sources array constitutes less than 1% of the total file size, with the vast majority of the payload comprised of sourcesContent and VLQ-encoded mappings. Parsing and re-stringifying this large structure generates significant V8 heap churn (5x to 6x transient allocations per sourcemap) and incurs 20 ms to 60 ms of single-threaded blocking time per chunk.

To eliminate redundant parsing and serialization overhead:

  • Scan the buffer to extract and parse only the sources JSON array.
  • Determine the node modules ignore list indices using the extracted sources array.
  • Splice the serialized x_google_ignoreList property directly into the output buffer adjacent to the root object delimiter without parsing or allocating intermediate strings for sourcesContent or mappings.
  • Gracefully fall back to full JSON parsing and serialization if non-standard JSON formatting is encountered.

In benchmarks on 2.4 MB to 10.4 MB sourcemap files, ignore-list processing dropped from 20.3 ms to 0.60 ms (33.9x faster) and 60.2 ms to 2.27 ms (26.5x faster), respectively, while reducing heap churn by more than 99%.

@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Sep 8, 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 introduces a fast-path optimization to update sourcemaps with the Chrome DevTools ignore list extension without fully parsing and stringifying the JSON. It adds helper functions extractSources and updateSourcemapFast to locate the "sources" array and inject the ignore list. The review feedback highlights three key issues: first, checking contents.includes(IGNORE_LIST_BYTES) to skip processing entirely can lead to silent bugs if the ignore list identifier is present in the source code content, so it should only bypass the fast path; second, the fallback slow path should check if the ignore list is already present in the parsed map to avoid duplicate insertions; and third, the parsed array in extractSources should be validated to ensure all elements are strings to prevent potential runtime errors.

Comment thread packages/angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin.ts Outdated
Comment thread packages/angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin.ts Outdated
@alan-agius4 alan-agius4 added the target: minor This PR is targeted for the next minor release label Sep 8, 2026
… ignore list

Previously, the sourcemap ignore-list plugin parsed the entire generated sourcemap buffer into a JavaScript object via JSON.parse and re-serialized it via JSON.stringify to inject x_google_ignoreList.

In typical applications, sourcemap files range from 2 MB to 10 MB+ each. The sources array constitutes less than 1% of the total file size, with the vast majority of the payload comprised of sourcesContent and VLQ-encoded mappings. Parsing and re-stringifying this large structure generates significant V8 heap churn (5x to 6x transient allocations per sourcemap) and incurs 20 ms to 60 ms of single-threaded blocking time per chunk.

To eliminate redundant parsing and serialization overhead:
- Scan the buffer to extract and parse only the sources JSON array.
- Determine the node modules ignore list indices using the extracted sources array.
- Splice the serialized x_google_ignoreList property directly into the output buffer adjacent to the root object delimiter without parsing or allocating intermediate strings for sourcesContent or mappings.
- Gracefully fall back to full JSON parsing and serialization if non-standard JSON formatting is encountered.

In benchmarks on 2.4 MB to 10.4 MB sourcemap files, ignore-list processing dropped from 20.3 ms to 0.60 ms (33.9x faster) and 60.2 ms to 2.27 ms (26.5x faster), respectively, while reducing heap churn by more than 99%.
@alan-agius4
alan-agius4 force-pushed the perf/sourcemap-ignorelist-splice branch from f8e5483 to e5ab123 Compare September 8, 2026 13:14
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 8, 2026
@alan-agius4
alan-agius4 requested a review from clydin September 8, 2026 14:56
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release and removed action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Sep 8, 2026
@alan-agius4
alan-agius4 merged commit 5a0d226 into angular:main Sep 8, 2026
42 checks passed
@alan-agius4
alan-agius4 deleted the perf/sourcemap-ignorelist-splice branch September 8, 2026 18:14
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

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

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 area: performance Issues related to performance target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants