From 47e4fb952baf324d3d3ac78ba0685447a575e261 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 3 Jun 2020 18:13:01 -0700 Subject: [PATCH 1/2] events: lazy load perf_hooks for EventTarget --- lib/internal/event_target.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 8641129b132914..3df88cedf58a3d 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -19,7 +19,6 @@ const { } } = require('internal/errors'); -const perf_hooks = require('perf_hooks'); const { customInspectSymbol } = require('internal/util'); const { inspect } = require('util'); @@ -30,11 +29,19 @@ const kTarget = Symbol('kTarget'); const kNewListener = Symbol('kNewListener'); const kRemoveListener = Symbol('kRemoveListener'); +// 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(); +} + class Event { #type = undefined; #defaultPrevented = false; #cancelable = false; - #timestamp = perf_hooks.performance.now(); + #timestamp = lazyNow(); // None of these are currently used in the Node.js implementation // of EventTarget because there is no concept of bubbling or From a19d755b13f4837bb98bb12469d1757479715d5e Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 8 Jun 2020 09:26:40 -0700 Subject: [PATCH 2/2] fixup! events: lazy load perf_hooks for EventTarget --- test/parallel/test-bootstrap-modules.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/parallel/test-bootstrap-modules.js b/test/parallel/test-bootstrap-modules.js index b2506499e7d1c7..86a91062ce7143 100644 --- a/test/parallel/test-bootstrap-modules.js +++ b/test/parallel/test-bootstrap-modules.js @@ -20,7 +20,6 @@ const expectedModules = new Set([ 'Internal Binding module_wrap', 'Internal Binding native_module', 'Internal Binding options', - 'Internal Binding performance', 'Internal Binding process_methods', 'Internal Binding report', 'Internal Binding string_decoder', @@ -31,7 +30,6 @@ const expectedModules = new Set([ 'Internal Binding types', 'Internal Binding url', 'Internal Binding util', - 'NativeModule async_hooks', 'NativeModule buffer', 'NativeModule events', 'NativeModule fs', @@ -49,7 +47,6 @@ const expectedModules = new Set([ 'NativeModule internal/fixed_queue', 'NativeModule internal/fs/dir', 'NativeModule internal/fs/utils', - 'NativeModule internal/histogram', 'NativeModule internal/idna', 'NativeModule internal/linkedlist', 'NativeModule internal/modules/run_main', @@ -86,7 +83,6 @@ const expectedModules = new Set([ 'NativeModule internal/validators', 'NativeModule internal/vm/module', 'NativeModule path', - 'NativeModule perf_hooks', 'NativeModule timers', 'NativeModule url', 'NativeModule util',