Skip to content

Commit bc71278

Browse files
committed
events: lazy load perf_hooks for EventTarget
PR-URL: #33717 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Zeyu Yang <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 5536044 commit bc71278

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/internal/event_target.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const {
1919
}
2020
} = require('internal/errors');
2121

22-
const perf_hooks = require('perf_hooks');
2322
const { customInspectSymbol } = require('internal/util');
2423
const { inspect } = require('util');
2524

@@ -30,11 +29,19 @@ const kTarget = Symbol('kTarget');
3029
const kNewListener = Symbol('kNewListener');
3130
const kRemoveListener = Symbol('kRemoveListener');
3231

32+
// Lazy load perf_hooks to avoid the additional overhead on startup
33+
let perf_hooks;
34+
function lazyNow() {
35+
if (perf_hooks === undefined)
36+
perf_hooks = require('perf_hooks');
37+
return perf_hooks.performance.now();
38+
}
39+
3340
class Event {
3441
#type = undefined;
3542
#defaultPrevented = false;
3643
#cancelable = false;
37-
#timestamp = perf_hooks.performance.now();
44+
#timestamp = lazyNow();
3845

3946
// None of these are currently used in the Node.js implementation
4047
// of EventTarget because there is no concept of bubbling or

test/parallel/test-bootstrap-modules.js

-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const expectedModules = new Set([
2121
'Internal Binding module_wrap',
2222
'Internal Binding native_module',
2323
'Internal Binding options',
24-
'Internal Binding performance',
2524
'Internal Binding process_methods',
2625
'Internal Binding report',
2726
'Internal Binding string_decoder',
@@ -32,7 +31,6 @@ const expectedModules = new Set([
3231
'Internal Binding types',
3332
'Internal Binding url',
3433
'Internal Binding util',
35-
'NativeModule async_hooks',
3634
'NativeModule buffer',
3735
'NativeModule events',
3836
'NativeModule fs',
@@ -50,7 +48,6 @@ const expectedModules = new Set([
5048
'NativeModule internal/fixed_queue',
5149
'NativeModule internal/fs/dir',
5250
'NativeModule internal/fs/utils',
53-
'NativeModule internal/histogram',
5451
'NativeModule internal/idna',
5552
'NativeModule internal/linkedlist',
5653
'NativeModule internal/modules/run_main',
@@ -88,7 +85,6 @@ const expectedModules = new Set([
8885
'NativeModule internal/vm/module',
8986
'NativeModule internal/worker/js_transferable',
9087
'NativeModule path',
91-
'NativeModule perf_hooks',
9288
'NativeModule timers',
9389
'NativeModule url',
9490
'NativeModule util',

0 commit comments

Comments
 (0)