From 70b31adffabf0e7fb57c06e02b4f75bf1a212f5e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Jun 2017 15:20:39 +0200 Subject: [PATCH] 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. PR-URL: https://github.com/nodejs/node/pull/13743 Reviewed-By: Luigi Pinca Reviewed-By: Timothy Gu Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Refael Ackermann --- lib/console.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/console.js b/lib/console.js index 642ef209d6..6358a3e19d 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); };