From 774302b9bbf527e0e954813fb25bc285fa398bc2 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Fri, 1 Oct 2021 12:17:16 +0200 Subject: [PATCH] perf(fetch): optimize fillHeaders() key iteration (#12287) Reduces self-time by ~70x (~70ms => ~1ms on 1M iters) for...in filtered by hasOwnProperty yields the same set of keys as Object.keys() --- ext/fetch/20_headers.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js index c35c745b58..04ff104a2d 100644 --- a/ext/fetch/20_headers.js +++ b/ext/fetch/20_headers.js @@ -29,7 +29,7 @@ ArrayPrototypeJoin, ArrayPrototypeSplice, ArrayPrototypeFilter, - ObjectKeys, + ObjectPrototypeHasOwnProperty, ObjectEntries, RegExpPrototypeTest, Symbol, @@ -76,7 +76,10 @@ appendHeader(headers, header[0], header[1]); } } else { - for (const key of ObjectKeys(object)) { + for (const key in object) { + if (!ObjectPrototypeHasOwnProperty(object, key)) { + continue; + } appendHeader(headers, key, object[key]); } }