mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
bootstrap: load perf_hooks eagerly during bootstrap
PR-URL: https://github.com/nodejs/node/pull/38971 Refs: https://github.com/nodejs/node/issues/35711 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
@@ -241,10 +241,9 @@ if (!config.noBrowserGlobals) {
|
||||
|
||||
defineOperation(globalThis, 'queueMicrotask', queueMicrotask);
|
||||
|
||||
defineLazyGlobal(globalThis, 'performance', () => {
|
||||
const { performance } = require('perf_hooks');
|
||||
return performance;
|
||||
});
|
||||
// https://www.w3.org/TR/hr-time-2/#the-performance-attribute
|
||||
defineReplacableAttribute(globalThis, 'performance',
|
||||
require('perf_hooks').performance);
|
||||
|
||||
// Non-standard extensions:
|
||||
defineOperation(globalThis, 'clearImmediate', timers.clearImmediate);
|
||||
@@ -494,20 +493,12 @@ function defineOperation(target, name, method) {
|
||||
});
|
||||
}
|
||||
|
||||
function defineLazyGlobal(target, name, loader) {
|
||||
let value;
|
||||
let overridden = false;
|
||||
// https://heycam.github.io/webidl/#Replaceable
|
||||
function defineReplacableAttribute(target, name, value) {
|
||||
ObjectDefineProperty(target, name, {
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
if (value === undefined && !overridden)
|
||||
value = loader();
|
||||
return value;
|
||||
},
|
||||
set(val) {
|
||||
value = val;
|
||||
overridden = true;
|
||||
}
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -59,13 +59,7 @@ const kRemoveListener = Symbol('kRemoveListener');
|
||||
const kIsNodeStyleListener = Symbol('kIsNodeStyleListener');
|
||||
const kTrustEvent = Symbol('kTrustEvent');
|
||||
|
||||
// Lazy load perf_hooks to avoid the additional overhead on startup
|
||||
let perf_hooks;
|
||||
function lazyNow() {
|
||||
if (perf_hooks === undefined)
|
||||
perf_hooks = require('perf_hooks');
|
||||
return perf_hooks.performance.now();
|
||||
}
|
||||
const { now } = require('internal/perf/utils');
|
||||
|
||||
// TODO(joyeecheung): V8 snapshot does not support instance member
|
||||
// initializers for now:
|
||||
@@ -98,7 +92,7 @@ class Event {
|
||||
this[kComposed] = !!composed;
|
||||
this[kType] = `${type}`;
|
||||
this[kDefaultPrevented] = false;
|
||||
this[kTimestamp] = lazyNow();
|
||||
this[kTimestamp] = now();
|
||||
this[kPropagationStopped] = false;
|
||||
if (options?.[kTrustEvent]) {
|
||||
isTrustedSet.add(this);
|
||||
|
||||
@@ -79,6 +79,7 @@ const expectedModules = new Set([
|
||||
'NativeModule internal/modules/esm/translators',
|
||||
'NativeModule internal/process/esm_loader',
|
||||
'NativeModule internal/options',
|
||||
'NativeModule internal/perf/event_loop_delay',
|
||||
'NativeModule internal/perf/event_loop_utilization',
|
||||
'NativeModule internal/perf/nodetiming',
|
||||
'NativeModule internal/perf/observe',
|
||||
@@ -126,6 +127,7 @@ const expectedModules = new Set([
|
||||
'NativeModule internal/blob',
|
||||
'NativeModule async_hooks',
|
||||
'NativeModule path',
|
||||
'NativeModule perf_hooks',
|
||||
'NativeModule querystring',
|
||||
'NativeModule stream',
|
||||
'NativeModule stream/promises',
|
||||
|
||||
Reference in New Issue
Block a user