Skip to content

Commit f40b5ed

Browse files
H4adruyadorno
authored andcommitted
perf_hooks: reduce overhead of new performance_entries
PR-URL: #49803 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent d44a812 commit f40b5ed

2 files changed

Lines changed: 52 additions & 10 deletions

File tree

‎benchmark/perf_hooks/timerfied.js‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
constassert=require('assert');
4+
constcommon=require('../common.js');
5+
6+
const{
7+
PerformanceObserver,
8+
performance,
9+
}=require('perf_hooks');
10+
11+
functionrandomFn(){
12+
returnMath.random();
13+
}
14+
15+
constbench=common.createBenchmark(main,{
16+
n: [1e5],
17+
observe: ['function'],
18+
});
19+
20+
let_result;
21+
22+
functionmain({ n, observe }){
23+
constobs=newPerformanceObserver(()=>{
24+
bench.end(n);
25+
});
26+
obs.observe({entryTypes: [observe],buffered: true});
27+
28+
consttimerfied=performance.timerify(randomFn);
29+
30+
bench.start();
31+
for(leti=0;i<n;i++)
32+
_result=timerfied();
33+
34+
// Avoid V8 deadcode (elimination)
35+
assert.ok(_result);
36+
}

‎lib/internal/perf/performance_entry.js‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const{
44
ObjectDefineProperties,
5-
ReflectConstruct,
65
Symbol,
76
}=primordials;
87

@@ -25,14 +24,17 @@ const kEntryType = Symbol('PerformanceEntry.EntryType');
2524
constkStartTime=Symbol('PerformanceEntry.StartTime');
2625
constkDuration=Symbol('PerformanceEntry.Duration');
2726
constkDetail=Symbol('NodePerformanceEntry.Detail');
27+
constkSkipThrow=Symbol('kSkipThrow');
2828

2929
functionisPerformanceEntry(obj){
3030
returnobj?.[kName]!==undefined;
3131
}
3232

3333
classPerformanceEntry{
34-
constructor(){
35-
thrownewERR_ILLEGAL_CONSTRUCTOR();
34+
constructor(skipThrowSymbol=undefined){
35+
if(skipThrowSymbol!==kSkipThrow){
36+
thrownewERR_ILLEGAL_CONSTRUCTOR();
37+
}
3638
}
3739

3840
getname(){
@@ -92,9 +94,11 @@ function initPerformanceEntry(entry, name, type, start, duration) {
9294
}
9395

9496
functioncreatePerformanceEntry(name,type,start,duration){
95-
returnReflectConstruct(functionPerformanceEntry(){
96-
initPerformanceEntry(this,name,type,start,duration);
97-
},[],PerformanceEntry);
97+
constentry=newPerformanceEntry(kSkipThrow);
98+
99+
initPerformanceEntry(entry,name,type,start,duration);
100+
101+
returnentry;
98102
}
99103

100104
/**
@@ -119,10 +123,12 @@ class PerformanceNodeEntry extends PerformanceEntry {
119123
}
120124

121125
functioncreatePerformanceNodeEntry(name,type,start,duration,detail){
122-
returnReflectConstruct(functionPerformanceNodeEntry(){
123-
initPerformanceEntry(this,name,type,start,duration);
124-
this[kDetail]=detail;
125-
},[],PerformanceNodeEntry);
126+
constentry=newPerformanceNodeEntry(kSkipThrow);
127+
128+
initPerformanceEntry(entry,name,type,start,duration);
129+
entry[kDetail]=detail;
130+
131+
returnentry;
126132
}
127133

128134
module.exports={

0 commit comments

Comments
 (0)