Skip to content

Commit afe3909

Browse files
authored
util: avoid run debug when enabled is false
it can improve performace 700x faster PR-URL: nodejs#57494 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jordan Harband <[email protected]>
1 parent 9640379 commit afe3909

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/internal/util/debuglog.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function lazyUtilColors() {
6262
return utilColors;
6363
}
6464

65-
function debuglogImpl(enabled, set, args) {
65+
function debuglogImpl(enabled, set) {
6666
if (debugImpls[set] === undefined) {
6767
if (enabled) {
6868
const pid = process.pid;
@@ -109,6 +109,8 @@ function debuglog(set, cb) {
109109
return enabled;
110110
};
111111
const logger = (...args) => {
112+
// Improve performance when debug is disabled, avoid calling `new SafeArrayIterator(args)`
113+
if (enabled === false) return;
112114
switch (args.length) {
113115
case 1: return debug(args[0]);
114116
case 2: return debug(args[0], args[1]);

0 commit comments

Comments
 (0)