Skip to content

Commit f36bee4

Browse files
fengmk2aduh95
authored andcommitted
util: avoid run debug when enabled is false
it can improve performace 700x faster PR-URL: #57494 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com>
1 parent 87e0dda commit f36bee4

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)