Skip to content

perf(cli): Hash debug ID input without concatenating it - #2602

Merged
BYK merged 1 commit into
mainfrom
byk/perf-debug-id-inject
Nov 30, 2026
Merged

BYK merged 1 commit into
mainfrom
byk/perf-debug-id-inject

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Three small performance fixes in the sourcemap debug ID inject path (packages/cli/src/lib/sourcemap/debug-id.ts). Debug IDs and inject behavior don't change.

  • Hash without concatenating. A new debug ID came from contentToDebugId(`${js}\0${map}`). That builds one big string, which V8 then flattens and encodes before hashing. contentToDebugId now takes several parts and passes each one to hash.update(), which gives the same digest. Both inputs are already in memory (the JS for the registration scans and the rewrite, the map for JSON.parse), so streaming from disk wouldn't save anything.
  • No repeated registration scan. When a file has a //# debugId= comment but doesn't register that ID at runtime, injectDebugId ran hasDebugIdRegistration twice with the same arguments. Now the second check only runs for an ID that came from the map.
  • Early return in readRegisteredDebugId. It stops at the second distinct registered ID. Results stay the same: nothing for no ID or several IDs, and the ID itself when there's exactly one.

Before and after

For a ~50 MB minified bundle with a 151 MB sourcemap on Node 24 (medians of 3 runs, each in a fresh process):

before after
hash step: time 367 ms 266 ms
hash step: added peak RSS +203 MB +0 MB
injectDebugId: time 1437 ms 1313 ms
injectDebugId: peak RSS 1218 MB 1017 MB

via @BYK.

--

View Session [Sentry]

The debug ID hash of a bundle and its sourcemap built `${js}\0${map}`
first. For a 50 MB bundle that copy added about 200 MB of peak RSS.
contentToDebugId now takes parts and feeds each to the hash, which
gives the same digest; a test pins the existing IDs.

Two scans also do less work:
- injectDebugId no longer repeats the runtime registration check for an
  ID it already checked from the //# debugId= comment.
- readRegisteredDebugId stops at the second distinct registered ID.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@sentry-junior
sentry-junior Bot requested a review from BYK November 30, 2026 12:23
@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 30, 2026 12:23pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 30, 2026 12:23pm UTC

Request Review

@github-actions github-actions Bot added the risk: low PR risk score: low label Nov 30, 2026
@BYK
BYK added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 5669166 Nov 30, 2026
28 checks passed
@BYK
BYK deleted the byk/perf-debug-id-inject branch November 30, 2026 12:58

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — ca390d7d Deployed Nov 30, 2026 by vercel[bot]
Preview – sentry-local — ca390d7d Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: low PR risk score: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant