summaryrefslogtreecommitdiff
path: root/lib/_http_outgoing.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-11-18 03:50:13 +0100
committerRich Trott <rtrott@gmail.com>2018-12-08 18:07:36 -0800
commita1a5c0419e62f9ae3bbef9fb04fac2d867c9e509 (patch)
treef16f613583bf968579933fe00678cd1efa3850f5 /lib/_http_outgoing.js
parentc3dd0d001abdb983d19987c76cad7ef30ef82a25 (diff)
downloadandroid-node-v8-a1a5c0419e62f9ae3bbef9fb04fac2d867c9e509.tar.gz
android-node-v8-a1a5c0419e62f9ae3bbef9fb04fac2d867c9e509.tar.bz2
android-node-v8-a1a5c0419e62f9ae3bbef9fb04fac2d867c9e509.zip
lib: improve error creation performance
In case of an error where we only care about a cleaned up stack trace it is cheaper to reset the stack trace limit for the error that is created. That way the stack frames do not have to be computed twice. PR-URL: https://github.com/nodejs/node/pull/24747 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'lib/_http_outgoing.js')
-rw-r--r--lib/_http_outgoing.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index eb68d091c6..80125f8c24 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -446,7 +446,13 @@ function matchHeader(self, state, field, value) {
function validateHeaderName(name) {
if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) {
+ // Reducing the limit improves the performance significantly. We do not
+ // lose the stack frames due to the `captureStackTrace()` function that is
+ // called later.
+ const tmpLimit = Error.stackTraceLimit;
+ Error.stackTraceLimit = 0;
const err = new ERR_INVALID_HTTP_TOKEN('Header name', name);
+ Error.stackTraceLimit = tmpLimit;
Error.captureStackTrace(err, validateHeaderName);
throw err;
}
@@ -454,12 +460,18 @@ function validateHeaderName(name) {
function validateHeaderValue(name, value) {
let err;
+ // Reducing the limit improves the performance significantly. We do not loose
+ // the stack frames due to the `captureStackTrace()` function that is called
+ // later.
+ const tmpLimit = Error.stackTraceLimit;
+ Error.stackTraceLimit = 0;
if (value === undefined) {
err = new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
} else if (checkInvalidHeaderChar(value)) {
debug('Header "%s" contains invalid characters', name);
err = new ERR_INVALID_CHAR('header content', name);
}
+ Error.stackTraceLimit = tmpLimit;
if (err !== undefined) {
Error.captureStackTrace(err, validateHeaderValue);
throw err;