From 9fac7911091da0cbca3169d4bcdd982e735193a5 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Wed, 30 Nov 2022 10:58:58 -0500 Subject: [PATCH] perf: improve isomorphic decode performance (#1791) --- lib/fetch/util.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/fetch/util.js b/lib/fetch/util.js index 4d21e2e17b9..f2fd1088629 100644 --- a/lib/fetch/util.js +++ b/lib/fetch/util.js @@ -863,6 +863,8 @@ function isReadableStreamLike (stream) { ) } +const MAXIMUM_ARGUMENT_LENGTH = 65535 + /** * @see https://infra.spec.whatwg.org/#isomorphic-decode * @param {number[]|Uint8Array} input @@ -871,13 +873,12 @@ function isomorphicDecode (input) { // 1. To isomorphic decode a byte sequence input, return a string whose code point // length is equal to input’s length and whose code points have the same values // as the values of input’s bytes, in the same order. - let output = '' - for (let i = 0; i < input.length; i++) { - output += String.fromCharCode(input[i]) + if (input.length < MAXIMUM_ARGUMENT_LENGTH) { + return String.fromCharCode(...input) } - return output + return input.reduce((previous, current) => previous + String.fromCharCode(current), '') } /**