From f0baeea135d03f073058bc4af519552f205dbc5f Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Jun 2017 15:20:39 +0200 Subject: [PATCH 1/2] console: use a plain object for the the error stack Using a object instead of an Error is sufficient as the Error itself won't be used but only the stack trace that would otherwise be created twice. This improves the overall .trace() performance. --- lib/console.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/console.js b/lib/console.js index 642ef209d6b975..6358a3e19d4b08 100644 --- a/lib/console.js +++ b/lib/console.js @@ -151,11 +151,10 @@ Console.prototype.timeEnd = function timeEnd(label) { Console.prototype.trace = function trace(...args) { - // TODO probably can to do this better with V8's debug object once that is - // exposed. - var err = new Error(); - err.name = 'Trace'; - err.message = util.format.apply(null, args); + const err = { + name: 'Trace', + message: util.format.apply(null, args) + }; Error.captureStackTrace(err, trace); this.error(err.stack); }; From e16faada930e16d3c51be185fce613990f2a0490 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Jun 2017 15:24:04 +0200 Subject: [PATCH 2/2] internal/errors: prevent stack recalculation Newer v8 versions exclude the constructor from the stack trace so the recalculation of the trace can be avoided. --- lib/internal/errors.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index fcfbdd24bf3925..5ada4cb7f40f67 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -28,7 +28,6 @@ function makeNodeError(Base) { constructor(key, ...args) { super(message(key, args)); this[kCode] = key; - Error.captureStackTrace(this, NodeError); } get name() {