Skip to content

Commit 56a674f

Browse files
committed
events: fix duplicate require which cause performance penalty
1 parent 31772a4 commit 56a674f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/events.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ const {
6363
},
6464
} = require('internal/errors');
6565

66-
const {
67-
inspect
68-
} = require('internal/util/inspect');
66+
let inspect;
6967

7068
const {
7169
validateAbortSignal,
@@ -372,7 +370,9 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
372370
}
373371

374372
let stringifiedEr;
375-
const { inspect } = require('internal/util/inspect');
373+
if (!inspect) {
374+
inspect = require('internal/util/inspect').inspect;
375+
}
376376
try {
377377
stringifiedEr = inspect(er);
378378
} catch {
@@ -464,6 +464,9 @@ function _addListener(target, type, listener, prepend) {
464464
m = _getMaxListeners(target);
465465
if (m > 0 && existing.length > m && !existing.warned) {
466466
existing.warned = true;
467+
if (!inspect) {
468+
inspect = require('internal/util/inspect').inspect;
469+
}
467470
// No error code for this since it is a Warning
468471
// eslint-disable-next-line no-restricted-syntax
469472
const w = new Error('Possible EventEmitter memory leak detected. ' +

0 commit comments

Comments
 (0)