Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
events: lazy load perf_hooks for EventTarget
  • Loading branch information
jasnell committed Jun 8, 2020
commit 47e4fb952baf324d3d3ac78ba0685447a575e261
11 changes: 9 additions & 2 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const {
}
} = require('internal/errors');

const perf_hooks = require('perf_hooks');
const { customInspectSymbol } = require('internal/util');
const { inspect } = require('util');

Expand All @@ -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
Expand Down