Skip to content

Commit

Permalink
perf(fetch): optimize fillHeaders() key iteration (denoland#12287)
Browse files Browse the repository at this point in the history
Reduces self-time by ~70x (~70ms => ~1ms on 1M iters)

for...in filtered by hasOwnProperty yields the same set of keys as Object.keys()
  • Loading branch information
AaronO authored Oct 1, 2021
1 parent 5065c7b commit f68825e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ext/fetch/20_headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
ArrayPrototypeJoin,
ArrayPrototypeSplice,
ArrayPrototypeFilter,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
ObjectEntries,
RegExpPrototypeTest,
Symbol,
Expand Down Expand Up @@ -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]);
}
}
Expand Down

0 comments on commit f68825e

Please sign in to comment.