Skip to content

Commit 42e49ec

Browse files
H4adtargos
authored andcommitted
perf_hooks: reduce overhead of new resource timings
PR-URL: #49837 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent c255575 commit 42e49ec

3 files changed

Lines changed: 33 additions & 27 deletions

File tree

‎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: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ function isPerformanceEntry(obj) {
3131
}
3232

3333
classPerformanceEntry{
34-
constructor(skipThrowSymbol=undefined){
34+
constructor(
35+
skipThrowSymbol=undefined,
36+
name=undefined,
37+
type=undefined,
38+
start=undefined,
39+
duration=undefined,
40+
){
3541
if(skipThrowSymbol!==kSkipThrow){
3642
thrownewERR_ILLEGAL_CONSTRUCTOR();
3743
}
44+
45+
initPerformanceEntry(this,name,type,start,duration);
3846
}
3947

4048
getname(){
@@ -94,11 +102,7 @@ function initPerformanceEntry(entry, name, type, start, duration) {
94102
}
95103

96104
functioncreatePerformanceEntry(name,type,start,duration){
97-
constentry=newPerformanceEntry(kSkipThrow);
98-
99-
initPerformanceEntry(entry,name,type,start,duration);
100-
101-
returnentry;
105+
returnnewPerformanceEntry(kSkipThrow,name,type,start,duration);
102106
}
103107

104108
/**
@@ -123,9 +127,8 @@ class PerformanceNodeEntry extends PerformanceEntry {
123127
}
124128

125129
functioncreatePerformanceNodeEntry(name,type,start,duration,detail){
126-
constentry=newPerformanceNodeEntry(kSkipThrow);
130+
constentry=newPerformanceNodeEntry(kSkipThrow,name,type,start,duration);
127131

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

131134
returnentry;
@@ -138,4 +141,5 @@ module.exports = {
138141
isPerformanceEntry,
139142
PerformanceNodeEntry,
140143
createPerformanceNodeEntry,
144+
kSkipThrow,
141145
};

‎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)