GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: optimize `prepareStackTrace` on builtin frames · nodejs/node@e4b795e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/fixtures
    • simple-error-stack.js
    • simple-error-stack.ts
  • lib/internal/source_map
    • prepare_stack_trace.js
    • source_map_cache.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/fixtures/simple-error-stack.js‎

Copy file name to clipboardExpand all lines: benchmark/fixtures/simple-error-stack.js
+11-10Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎benchmark/fixtures/simple-error-stack.ts‎

Copy file name to clipboardExpand all lines: benchmark/fixtures/simple-error-stack.ts
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
const lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
66

77
function simpleErrorStack() {
8-
try {
9-
(lorem as any).BANG();
10-
} catch (e) {
11-
return e.stack;
12-
}
8+
[1].map(() => {
9+
try {
10+
(lorem as any).BANG();
11+
} catch (e) {
12+
return e.stack;
13+
}
14+
})
1315
}
1416

1517
export {
Collapse file

‎lib/internal/source_map/prepare_stack_trace.js‎

Copy file name to clipboardExpand all lines: lib/internal/source_map/prepare_stack_trace.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ function prepareStackTraceWithSourceMaps(error, trace) {
5353
const sm = fileName === lastFileName ?
5454
lastSourceMap :
5555
findSourceMap(fileName);
56-
lastSourceMap = sm;
57-
lastFileName = fileName;
56+
// Only when a source map is found, cache it for the next iteration.
57+
// This is a performance optimization to avoid interleaving with JS builtin function
58+
// invalidating the cache.
59+
// - at myFunc (file:///path/to/file.js:1:2)
60+
// - at Array.map (<anonymous>)
61+
// - at myFunc (file:///path/to/file.js:3:4)
5862
if (sm) {
63+
lastSourceMap = sm;
64+
lastFileName = fileName;
5965
return `${kStackLineAt}${serializeJSStackFrame(sm, callSite, trace[i + 1])}`;
6066
}
6167
} catch (err) {
Collapse file

‎lib/internal/source_map/source_map_cache.js‎

Copy file name to clipboardExpand all lines: lib/internal/source_map/source_map_cache.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ function findSourceMap(sourceURL) {
347347
return undefined;
348348
}
349349

350+
// No source maps for builtin modules.
351+
if (sourceURL.startsWith('node:')) {
352+
return undefined;
353+
}
354+
350355
SourceMap ??= require('internal/source_map/source_map').SourceMap;
351356
try {
352357
if (RegExpPrototypeExec(kLeadingProtocol, sourceURL) === null) {

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.