8000 Improve core logging performance · mKoder/log4js-node@0af3f16 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0af3f16

Browse files
committed
Improve core logging performance
Allow V8 to optimize functions by not leaking the arguments object. This results in a performance improvement of about 20%.
1 parent 7368cd3 commit 0af3f16

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/layouts.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function wrapErrorsWithInspect(items) {
3333
if (semver.satisfies(process.version, '>=6')) {
3434
return util.format(item);
3535
} else {
36-
return util.format(item) + '\n' + item.stack;
36+
return util.format(item) + '\n' + item.stack;
3737
}
3838
} };
3939
} else {
@@ -43,7 +43,14 @@ function wrapErrorsWithInspect(items) {
4343
}
4444

4545
function formatLogData(logData) {
46-
var data = Array.isArray(logData) ? logData : Array.prototype.slice.call(arguments);
46+
var data = logData;
47+
if (!Array.isArray(da 8000 ta)) {
48+
var numArgs = arguments.length;
49+
data = new Array(numArgs);
50+
for (var i = 0; i < numArgs; i++) {
51+
data[i] = arguments[i];
52+
}
53+
}
4754
return util.format.apply(util, wrapErrorsWithInspect(data));
4855
}
4956

lib/logger.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ function addLevelMethods(level) {
8282
Logger.prototype[levelMethod] = function () {
8383
if (logWritesEnabled && this.isLevelEnabled(level)) {
8484
var numArgs = arguments.length;
85-
var args = Array.prototype.slice.call(arguments);
85+
var args = new Array(numArgs);
86+
for (var i = 0; i < numArgs; i++) {
87+
args[i] = arguments[i];
88+
}
8689
this._log(level, args);
8790
}
8891
};

0 commit comments

Comments
 (0)
0