diff options
author | James M Snell <jasnell@gmail.com> | 2020-06-04 04:13:01 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2020-06-16 22:27:23 +0300 |
commit | bc71278563b60caba7e2d39c170d439a205ff529 (patch) | |
tree | 135dea2250af466c80addd13161ff34237681eac /lib/internal/event_target.js | |
parent | 55360443ced34515c775c5beb29f907de671dffe (diff) |
events: lazy load perf_hooks for EventTarget
PR-URL: https://github.com/nodejs/node/pull/33717
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/internal/event_target.js')
-rw-r--r-- | lib/internal/event_target.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 8641129b132..3df88cedf58 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 |