Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c844d22

Browse filesBrowse files
mmomtchevdanielleadams
authored andcommitted
errors: eliminate all overhead for hidden calls
Eliminate all overhead for function calls that are to be hidden from the stack traces at the expense of reduced performance for the error case Fixes: #35386 PR-URL: #35644 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 5e499c4 commit c844d22
Copy full SHA for c844d22

File tree

Expand file treeCollapse file tree

3 files changed

+205
-150
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+205
-150
lines changed
Open diff view settings
Collapse file

‎benchmark/misc/hidestackframes.js‎

Copy file name to clipboard
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
type: ['hide-stackframes-throw', 'direct-call-throw',
7+
'hide-stackframes-noerr', 'direct-call-noerr'],
8+
n: [10e4]
9+
}, {
10+
flags: ['--expose-internals']
11+
});
12+
13+
function main({ n, type }) {
14+
const {
15+
hideStackFrames,
16+
codes: {
17+
ERR_INVALID_ARG_TYPE,
18+
},
19+
} = require('internal/errors');
20+
21+
const testfn = (value) => {
22+
if (typeof value !== 'number') {
23+
throw new ERR_INVALID_ARG_TYPE('Benchmark', 'number', value);
24+
}
25+
};
26+
27+
let fn = testfn;
28+
if (type.startsWith('hide-stackframe'))
29+
fn = hideStackFrames(testfn);
30+
let value = 42;
31+
if (type.endsWith('-throw'))
32+
value = 'err';
33+
34+
bench.start();
35+
36+
for (let i = 0; i < n; i++) {
37+
try {
38+
fn(value);
39+
} catch {
40+
// No-op
41+
}
42+
}
43+
44+
bench.end(n);
45+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.