Skip to content

Commit

Permalink
bootstrap: lazy-load Performance.prototype.timeOrigin
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung authored and panva committed Jan 31, 2023
1 parent fcfde34 commit 4d7d200
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
29 changes: 14 additions & 15 deletions lib/internal/perf/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,24 @@ ObjectDefineProperties(Performance.prototype, {
enumerable: false,
value: timerify,
},
// This would be updated during pre-execution in case
// the process is launched from a snapshot.
// TODO(joyeecheung): we may want to warn about access to
// this during snapshot building.
timeOrigin: {
__proto__: null,
configurable: true,
enumerable: true,
value: getTimeOriginTimestamp(),
get() {
let value = getTimeOriginTimestamp();
ObjectDefineProperty(Performance.prototype, 'timeOrigin', {
__proto__: null,
value,
});
return value;
},
set(value) {
ObjectDefineProperty(Performance.prototype, 'timeOrigin', {
__proto__: null,
value,
});
}
},
toJSON: {
__proto__: null,
Expand All @@ -224,15 +233,6 @@ ObjectDefineProperties(Performance.prototype, {
}
});

function refreshTimeOrigin() {
ObjectDefineProperty(Performance.prototype, 'timeOrigin', {
__proto__: null,
configurable: true,
enumerable: true,
value: getTimeOriginTimestamp(),
});
}

const performance = new InternalPerformance();

function dispatchBufferFull(type) {
Expand All @@ -246,5 +246,4 @@ setDispatchBufferFull(dispatchBufferFull);
module.exports = {
Performance,
performance,
refreshTimeOrigin
};
1 change: 0 additions & 1 deletion lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ function setupTraceCategoryState() {
}

function setupPerfHooks() {
require('internal/perf/performance').refreshTimeOrigin();
require('internal/perf/utils').refreshTimeOrigin();
}

Expand Down

0 comments on commit 4d7d200

Please sign in to comment.