Skip to content

Commit

Permalink
events: fix duplicate require which cause performance penalty
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwzbwcom committed Aug 26, 2021
1 parent 31772a4 commit 56a674f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ const {
},
} = require('internal/errors');

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

const {
validateAbortSignal,
Expand Down Expand Up @@ -372,7 +370,9 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
}

let stringifiedEr;
const { inspect } = require('internal/util/inspect');
if (!inspect) {
inspect = require('internal/util/inspect').inspect;
}
try {
stringifiedEr = inspect(er);
} catch {
Expand Down Expand Up @@ -464,6 +464,9 @@ function _addListener(target, type, listener, prepend) {
m = _getMaxListeners(target);
if (m > 0 && existing.length > m && !existing.warned) {
existing.warned = true;
if (!inspect) {
inspect = require('internal/util/inspect').inspect;
}
// No error code for this since it is a Warning
// eslint-disable-next-line no-restricted-syntax
const w = new Error('Possible EventEmitter memory leak detected. ' +
Expand Down

0 comments on commit 56a674f

Please sign in to comment.