From f6b4d12a1f85cfe70819f42c59fd23464777ff4f Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 16 Mar 2025 19:02:06 +0800 Subject: [PATCH] util: avoid run debug when enabled is false it can improve performace 700x faster --- lib/internal/util/debuglog.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 96b10c4bbac767..3c8328b31b5565 100644 --- a/lib/internal/util/debuglog.js +++ b/lib/internal/util/debuglog.js @@ -62,7 +62,7 @@ function lazyUtilColors() { return utilColors; } -function debuglogImpl(enabled, set, args) { +function debuglogImpl(enabled, set) { if (debugImpls[set] === undefined) { if (enabled) { const pid = process.pid; @@ -109,6 +109,8 @@ function debuglog(set, cb) { return enabled; }; const logger = (...args) => { + // Improve performance when debug is disabled, avoid calling `new SafeArrayIterator(args)` + if (enabled === false) return; switch (args.length) { case 1: return debug(args[0]); case 2: return debug(args[0], args[1]);