Skip to content

Commit f6ff458

Browse files
committed
perf_hooks: reduce overhead of new user timings
1 parent 3838b57 commit f6ff458

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

lib/internal/perf/performance_entry.js

+1
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,5 @@ module.exports = {
138138
isPerformanceEntry,
139139
PerformanceNodeEntry,
140140
createPerformanceNodeEntry,
141+
kSkipThrow,
141142
};

lib/internal/perf/usertiming.js

+22-12
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 { initPerformanceEntry, PerformanceEntry, kSkipThrow } = require('internal/perf/performance_entry');
1513
const { now } = require('internal/perf/utils');
1614
const { enqueue, bufferUserTiming } = require('internal/perf/observe');
1715
const nodeTiming = require('internal/perf/nodetiming');
@@ -69,7 +67,7 @@ function getMark(name) {
6967
return ts;
7068
}
7169

72-
class PerformanceMark {
70+
class PerformanceMark extends PerformanceEntry {
7371
constructor(name, options = kEmptyObject) {
7472
if (arguments.length === 0) {
7573
throw new ERR_MISSING_ARGS('name');
@@ -89,6 +87,7 @@ class PerformanceMark {
8987
detail = detail != null ?
9088
structuredClone(detail) :
9189
null;
90+
super(kSkipThrow);
9291
initPerformanceEntry(this, name, 'mark', startTime, 0);
9392
this[kDetail] = detail;
9493
}
@@ -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,19 @@ ObjectDefineProperties(PerformanceMark.prototype, {
120118
});
121119

122120
class PerformanceMeasure extends PerformanceEntry {
123-
constructor() {
124-
throw new ERR_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+
throw new ERR_ILLEGAL_CONSTRUCTOR();
130+
}
131+
132+
super(skipThrowSymbol);
133+
initPerformanceEntry(this, name, type, start, duration);
125134
}
126135

127136
get detail() {
@@ -139,10 +148,11 @@ ObjectDefineProperties(PerformanceMeasure.prototype, {
139148
});
140149

141150
function createPerformanceMeasure(name, start, duration, detail) {
142-
return ReflectConstruct(function PerformanceMeasure() {
143-
initPerformanceEntry(this, name, 'measure', start, duration);
144-
this[kDetail] = detail;
145-
}, [], PerformanceMeasure);
151+
const measure = new PerformanceMeasure(kSkipThrow, name, 'measure', start, duration);
152+
153+
measure[kDetail] = detail;
154+
155+
return measure;
146156
}
147157

148158
function mark(name, options) {

0 commit comments

Comments
 (0)