Skip to content

Commit

Permalink
perf_hooks: reduce overhead of new user timings
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Sep 28, 2023
1 parent 3838b57 commit f6ff458
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/internal/perf/performance_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ module.exports = {
isPerformanceEntry,
PerformanceNodeEntry,
createPerformanceNodeEntry,
kSkipThrow,
};
34 changes: 22 additions & 12 deletions lib/internal/perf/usertiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

const {
ObjectDefineProperties,
ObjectSetPrototypeOf,
SafeMap,
SafeSet,
SafeArrayIterator,
Symbol,
SymbolToStringTag,
ReflectConstruct,
} = primordials;

const { initPerformanceEntry, PerformanceEntry } = require('internal/perf/performance_entry');
const { initPerformanceEntry, PerformanceEntry, kSkipThrow } = require('internal/perf/performance_entry');
const { now } = require('internal/perf/utils');
const { enqueue, bufferUserTiming } = require('internal/perf/observe');
const nodeTiming = require('internal/perf/nodetiming');
Expand Down Expand Up @@ -69,7 +67,7 @@ function getMark(name) {
return ts;
}

class PerformanceMark {
class PerformanceMark extends PerformanceEntry {
constructor(name, options = kEmptyObject) {
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('name');
Expand All @@ -89,6 +87,7 @@ class PerformanceMark {
detail = detail != null ?
structuredClone(detail) :
null;
super(kSkipThrow);
initPerformanceEntry(this, name, 'mark', startTime, 0);
this[kDetail] = detail;
}
Expand All @@ -108,8 +107,7 @@ class PerformanceMark {
};
}
}
ObjectSetPrototypeOf(PerformanceMark, PerformanceEntry);
ObjectSetPrototypeOf(PerformanceMark.prototype, PerformanceEntry.prototype);

ObjectDefineProperties(PerformanceMark.prototype, {
detail: kEnumerableProperty,
[SymbolToStringTag]: {
Expand All @@ -120,8 +118,19 @@ ObjectDefineProperties(PerformanceMark.prototype, {
});

class PerformanceMeasure extends PerformanceEntry {
constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
constructor(
skipThrowSymbol = undefined,
name = undefined,
type = undefined,
start = undefined,
duration = undefined,
) {
if (skipThrowSymbol !== kSkipThrow) {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}

super(skipThrowSymbol);
initPerformanceEntry(this, name, type, start, duration);
}

get detail() {
Expand All @@ -139,10 +148,11 @@ ObjectDefineProperties(PerformanceMeasure.prototype, {
});

function createPerformanceMeasure(name, start, duration, detail) {
return ReflectConstruct(function PerformanceMeasure() {
initPerformanceEntry(this, name, 'measure', start, duration);
this[kDetail] = detail;
}, [], PerformanceMeasure);
const measure = new PerformanceMeasure(kSkipThrow, name, 'measure', start, duration);

measure[kDetail] = detail;

return measure;
}

function mark(name, options) {
Expand Down

0 comments on commit f6ff458

Please sign in to comment.