Skip to content

Commit

Permalink
perf(webidl): optimize createRecordConverter() (#12286)
Browse files Browse the repository at this point in the history
Cuts self-time by ~6x, 172ns/iter => 22ns/iter benched on 1M Response builds / HeadersInit calls
  • Loading branch information
AaronO authored and ry committed Oct 4, 2021
1 parent 7260b29 commit 2304a69
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ext/webidl/00_webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"use strict";

((window) => {
const core = window.Deno.core;
const {
ArrayBuffer,
ArrayBufferIsView,
Expand Down Expand Up @@ -48,6 +49,7 @@
ObjectGetOwnPropertyDescriptor,
ObjectGetOwnPropertyDescriptors,
ObjectGetPrototypeOf,
ObjectPrototypeHasOwnProperty,
ObjectIs,
PromisePrototypeThen,
PromiseReject,
Expand Down Expand Up @@ -844,8 +846,21 @@
opts,
);
}
const keys = ReflectOwnKeys(V);
const result = {};
// Fast path for common case (not a Proxy)
if (!core.isProxy(V)) {
for (const key in V) {
if (!ObjectPrototypeHasOwnProperty(V, key)) {
continue;
}
const typedKey = keyConverter(key, opts);
const value = V[key];
const typedValue = valueConverter(value, opts);
result[typedKey] = typedValue;
}
}
// Slow path if Proxy (e.g: in WPT tests)
const keys = ReflectOwnKeys(V);
for (const key of keys) {
const desc = ObjectGetOwnPropertyDescriptor(V, key);
if (desc !== undefined && desc.enumerable === true) {
Expand Down

0 comments on commit 2304a69

Please sign in to comment.