Repository navigation
fix(sourcemaps): reduce debug ID registration stack capture - #2542
Conversation
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🔗 Commit SHA: 921e090 | Docs | View more details | Give us feedback! |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The snippet leaves an observable stackTraceLimit property behind when the property was initially absent.
Review effort: Balanced
Findings: 1
What changed in this PR
Reduces sourcemap debug-ID registration overhead by limiting V8 stack capture to one frame.
Changes:
- Temporarily sets and restores
Error.stackTraceLimit. - Adds runtime coverage for restoration and failure scenarios.
- Verifies generated bundles contain the optimization.
| File | Description |
|---|---|
debugId.ts |
Updates the injected registration snippet. |
debugId.test.ts |
Tests stack limits and failure handling. |
inject.test.ts |
Verifies optimized snippet injection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| `(function(c,n){try{if(typeof window==='undefined')return;var w=window,m=w[n]=w[n]||{},s=new Error().stack;s&&(m[s]=c)}catch(e){}})({"ddDebugId":"${debugId}"},"${SOURCE_CODE_CONTEXT_MARKER}");` | ||
| const buildSnippet = (debugId: string): string => { | ||
| // Restore before reading .stack so prepareStackTrace sees the application setting. | ||
| return `(function(c,n){try{if(typeof window==='undefined')return;var w=window,m=w[n]=w[n]||{},l=Error.stackTraceLimit;try{Error.stackTraceLimit=1;var e=new Error()}finally{Error.stackTraceLimit=l}var s=e.stack;s&&(m[s]=c)}catch(e){}})({"ddDebugId":"${debugId}"},"${SOURCE_CODE_CONTEXT_MARKER}");` |
There was a problem hiding this comment.
This was introduced by the simplification on d3280b4
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|

Reading the debug-ID registration stack can trigger expensive source-position collection in V8 for large bundles. Temporarily set
Error.stackTraceLimitto1while creating the registration error, restoring the original value infinallybefore formatting its stack.This is the default behavior; no CLI flag is required. Engines without support ignore the setting for stack capture. Capture failures are caught so application execution continues. Custom Error constructors can observe the temporary limit, and custom stack formatters receive fewer registration frames. Already-injected bundles are skipped; rebuild fresh artifacts to adopt the change.
Benchmark examples
Median cold bundle-evaluation time over 30 trials per variant, using synthetic ESM bundles in standalone headless Chrome 154 on an Apple M1 Max. No inspector or CPU sampling was enabled. The baseline removes the registration snippet; application bodies are identical across variants. These measurements used the earlier one-frame implementation with descriptor checks. The final snippet removes those checks; the table has not been rerun for that exact revision.
These measure bundle evaluation, not download time or Web Vitals. Warm synthetic runs showed no meaningful benefit; warm application-bundle results remain inconclusive. Performance improvement depends on the workload. Benchmark scripts and raw results are excluded from this PR.
Context of the problem
V8 reduces startup work by postponing source-position collection.
Error.stacktriggers the collection of source positions, which can impact performance.Described: lazy-source-positions
Solution:

Use stackTraceLimit
Tests
Adds runtime tests covering:
Existing injection tests verify original sourcemap positions, matching bundle/sourcemap IDs, default one-frame capture, dry-run behavior, and skipping already-injected bundles.
Validation: build, lint, README usage check, and all 123 sourcemaps tests pass. Separate local checks of the same capture snippet with RUM SDK 7.15.0 confirmed immediate, microtask, and cross-file debug-ID resolution in Chrome, Firefox, and WebKit; these browser checks are not added to CI.
Related to #2537.