Skip to content

Commit cdcfc29

Browse files
committed
perf_hooks: reduce overhead of new resource timings
1 parent 3838b57 commit cdcfc29

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

‎benchmark/perf_hooks/resourcetiming.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ function main({n, observe }){
7272
obs.observe({entryTypes: [observe],buffered: true});
7373

7474
bench.start();
75-
for(leti=0;i<1e5;i++)
75+
for(leti=0;i<n;i++)
7676
test();
7777
}

‎lib/internal/perf/performance_entry.js‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ function isPerformanceEntry(obj){
3131
}
3232

3333
classPerformanceEntry{
34-
constructor(skipThrowSymbol=undefined){
34+
constructor(skipThrowSymbol=undefined,name=undefined,type=undefined,start=undefined,duration=undefined){
3535
if(skipThrowSymbol!==kSkipThrow){
3636
thrownewERR_ILLEGAL_CONSTRUCTOR();
3737
}
38+
39+
initPerformanceEntry(this,name,type,start,duration);
3840
}
3941

4042
getname(){
@@ -94,11 +96,7 @@ function initPerformanceEntry(entry, name, type, start, duration){
9496
}
9597

9698
functioncreatePerformanceEntry(name,type,start,duration){
97-
constentry=newPerformanceEntry(kSkipThrow);
98-
99-
initPerformanceEntry(entry,name,type,start,duration);
100-
101-
returnentry;
99+
returnnewPerformanceEntry(kSkipThrow,name,type,start,duration);
102100
}
103101

104102
/**
@@ -123,9 +121,8 @@ class PerformanceNodeEntry extends PerformanceEntry{
123121
}
124122

125123
functioncreatePerformanceNodeEntry(name,type,start,duration,detail){
126-
constentry=newPerformanceNodeEntry(kSkipThrow);
124+
constentry=newPerformanceNodeEntry(kSkipThrow,name,type,start,duration);
127125

128-
initPerformanceEntry(entry,name,type,start,duration);
129126
entry[kDetail]=detail;
130127

131128
returnentry;
@@ -138,4 +135,5 @@ module.exports ={
138135
isPerformanceEntry,
139136
PerformanceNodeEntry,
140137
createPerformanceNodeEntry,
138+
kSkipThrow,
141139
};

‎lib/internal/perf/resource_timing.js‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33

44
const{
55
ObjectDefineProperties,
6-
ObjectSetPrototypeOf,
7-
ReflectConstruct,
86
Symbol,
97
SymbolToStringTag,
108
}=primordials;
11-
const{ initPerformanceEntry, PerformanceEntry }=require('internal/perf/performance_entry');
12-
constassert=require('internal/assert');
13-
const{ enqueue, bufferResourceTiming }=require('internal/perf/observe');
149
const{
1510
codes: {
1611
ERR_ILLEGAL_CONSTRUCTOR,
1712
},
1813
}=require('internal/errors');
14+
const{ PerformanceEntry, kSkipThrow }=require('internal/perf/performance_entry');
15+
constassert=require('internal/assert');
16+
const{ enqueue, bufferResourceTiming }=require('internal/perf/observe');
1917
const{ validateInternalField }=require('internal/validators');
2018
const{ kEnumerableProperty }=require('internal/util');
2119

@@ -25,8 +23,12 @@ const kTimingInfo = Symbol('kTimingInfo');
2523
constkInitiatorType=Symbol('kInitiatorType');
2624

2725
classPerformanceResourceTimingextendsPerformanceEntry{
28-
constructor(){
29-
thrownewERR_ILLEGAL_CONSTRUCTOR();
26+
constructor(skipThrowSymbol=undefined,name=undefined,type=undefined){
27+
if(skipThrowSymbol!==kSkipThrow){
28+
thrownewERR_ILLEGAL_CONSTRUCTOR();
29+
}
30+
31+
super(skipThrowSymbol,name,type);
3032
}
3133

3234
getname(){
@@ -189,16 +191,17 @@ ObjectDefineProperties(PerformanceResourceTiming.prototype,{
189191
});
190192

191193
functioncreatePerformanceResourceTiming(requestedUrl,initiatorType,timingInfo,cacheMode=''){
192-
returnReflectConstruct(functionPerformanceResourceTiming(){
193-
initPerformanceEntry(this,requestedUrl,'resource');
194-
this[kInitiatorType]=initiatorType;
195-
this[kRequestedUrl]=requestedUrl;
196-
// https://fetch.spec.whatwg.org/#fetch-timing-info
197-
// This class is using timingInfo assuming it's already validated.
198-
// The spec doesn't say to validate it in the class construction.
199-
this[kTimingInfo]=timingInfo;
200-
this[kCacheMode]=cacheMode;
201-
},[],PerformanceResourceTiming);
194+
constresourceTiming=newPerformanceResourceTiming(kSkipThrow,requestedUrl,'resource');
195+
196+
resourceTiming[kInitiatorType]=initiatorType;
197+
resourceTiming[kRequestedUrl]=requestedUrl;
198+
// https://fetch.spec.whatwg.org/#fetch-timing-info
199+
// This class is using timingInfo assuming it's already validated.
200+
// The spec doesn't say to validate it in the class construction.
201+
resourceTiming[kTimingInfo]=timingInfo;
202+
resourceTiming[kCacheMode]=cacheMode;
203+
204+
returnresourceTiming;
202205
}
203206

204207
// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
@@ -221,7 +224,6 @@ function markResourceTiming(
221224
cacheMode,
222225
);
223226

224-
ObjectSetPrototypeOf(resource,PerformanceResourceTiming.prototype);
225227
enqueue(resource);
226228
bufferResourceTiming(resource);
227229
returnresource;

0 commit comments

Comments
(0)