Skip to content

Commit e8f024b

Browse files
H4adtargos
authored andcommitted
perf_hooks: reduce overhead of new user timings
PR-URL: #49914 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent 17581c2 commit e8f024b

2 files changed

Lines changed: 32 additions & 28 deletions

File tree

‎lib/internal/perf/performance_entry.js‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ class PerformanceEntry {
4242
thrownewERR_ILLEGAL_CONSTRUCTOR();
4343
}
4444

45-
initPerformanceEntry(this,name,type,start,duration);
45+
this[kName]=name;
46+
this[kEntryType]=type;
47+
this[kStartTime]=start;
48+
this[kDuration]=duration;
4649
}
4750

4851
getname(){
@@ -94,13 +97,6 @@ ObjectDefineProperties(PerformanceEntry.prototype, {
9497
toJSON: kEnumerableProperty,
9598
});
9699

97-
functioninitPerformanceEntry(entry,name,type,start,duration){
98-
entry[kName]=name;
99-
entry[kEntryType]=type;
100-
entry[kStartTime]=start;
101-
entry[kDuration]=duration;
102-
}
103-
104100
functioncreatePerformanceEntry(name,type,start,duration){
105101
returnnewPerformanceEntry(kSkipThrow,name,type,start,duration);
106102
}
@@ -135,7 +131,6 @@ function createPerformanceNodeEntry(name, type, start, duration, detail) {
135131
}
136132

137133
module.exports={
138-
initPerformanceEntry,
139134
createPerformanceEntry,
140135
PerformanceEntry,
141136
isPerformanceEntry,

‎lib/internal/perf/usertiming.js‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
const{
44
ObjectDefineProperties,
5-
ObjectSetPrototypeOf,
65
SafeMap,
76
SafeSet,
87
SafeArrayIterator,
98
Symbol,
109
SymbolToStringTag,
11-
ReflectConstruct,
1210
}=primordials;
1311

14-
const{initPerformanceEntry, PerformanceEntry}=require('internal/perf/performance_entry');
12+
const{PerformanceEntry, kSkipThrow}=require('internal/perf/performance_entry');
1513
const{ now }=require('internal/perf/utils');
1614
const{ enqueue, bufferUserTiming }=require('internal/perf/observe');
1715
constnodeTiming=require('internal/perf/nodetiming');
@@ -35,7 +33,6 @@ const {
3533

3634
const{ structuredClone }=require('internal/structured_clone');
3735
const{
38-
kEmptyObject,
3936
lazyDOMException,
4037
kEnumerableProperty,
4138
}=require('internal/util');
@@ -69,27 +66,29 @@ function getMark(name) {
6966
returnts;
7067
}
7168

72-
classPerformanceMark{
73-
constructor(name,options=kEmptyObject){
69+
classPerformanceMarkextendsPerformanceEntry{
70+
constructor(name,options=undefined){
7471
if(arguments.length===0){
7572
thrownewERR_MISSING_ARGS('name');
7673
}
7774
name=`${name}`;
78-
options??=kEmptyObject;
7975
if(nodeTimingReadOnlyAttributes.has(name))
8076
thrownewERR_INVALID_ARG_VALUE('name',name);
81-
validateObject(options,'options');
82-
conststartTime=options.startTime??now();
77+
if(options!=null){
78+
validateObject(options,'options');
79+
}
80+
conststartTime=options?.startTime??now();
8381
validateNumber(startTime,'startTime');
8482
if(startTime<0)
8583
thrownewERR_PERFORMANCE_INVALID_TIMESTAMP(startTime);
8684
markTimings.set(name,startTime);
8785

88-
letdetail=options.detail;
86+
letdetail=options?.detail;
8987
detail=detail!=null ?
9088
structuredClone(detail) :
9189
null;
92-
initPerformanceEntry(this,name,'mark',startTime,0);
90+
91+
super(kSkipThrow,name,'mark',startTime,0);
9392
this[kDetail]=detail;
9493
}
9594

@@ -108,8 +107,7 @@ class PerformanceMark {
108107
};
109108
}
110109
}
111-
ObjectSetPrototypeOf(PerformanceMark,PerformanceEntry);
112-
ObjectSetPrototypeOf(PerformanceMark.prototype,PerformanceEntry.prototype);
110+
113111
ObjectDefineProperties(PerformanceMark.prototype,{
114112
detail: kEnumerableProperty,
115113
[SymbolToStringTag]: {
@@ -120,8 +118,18 @@ ObjectDefineProperties(PerformanceMark.prototype, {
120118
});
121119

122120
classPerformanceMeasureextendsPerformanceEntry{
123-
constructor(){
124-
thrownewERR_ILLEGAL_CONSTRUCTOR();
121+
constructor(
122+
skipThrowSymbol=undefined,
123+
name=undefined,
124+
type=undefined,
125+
start=undefined,
126+
duration=undefined,
127+
){
128+
if(skipThrowSymbol!==kSkipThrow){
129+
thrownewERR_ILLEGAL_CONSTRUCTOR();
130+
}
131+
132+
super(skipThrowSymbol,name,type,start,duration);
125133
}
126134

127135
getdetail(){
@@ -139,10 +147,11 @@ ObjectDefineProperties(PerformanceMeasure.prototype, {
139147
});
140148

141149
functioncreatePerformanceMeasure(name,start,duration,detail){
142-
returnReflectConstruct(functionPerformanceMeasure(){
143-
initPerformanceEntry(this,name,'measure',start,duration);
144-
this[kDetail]=detail;
145-
},[],PerformanceMeasure);
150+
constmeasure=newPerformanceMeasure(kSkipThrow,name,'measure',start,duration);
151+
152+
measure[kDetail]=detail;
153+
154+
returnmeasure;
146155
}
147156

148157
functionmark(name,options){

0 commit comments

Comments
 (0)