Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(http): cache webidl.converters lookups in ext/fetch/23_response.js #26256

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Format
  • Loading branch information
dsherret committed Oct 15, 2024
commit 44073d6461b6be51e9a3ad12093448bb8174b35a
92 changes: 47 additions & 45 deletions ext/fetch/23_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ const _body = Symbol("body");
const _brand = webidl.brand;

// it's slightly faster to cache these
const webidlConvertersBodyInitDomString = webidl.converters["BodyInit_DOMString?"];
const webidlConvertersUSVString = webidl.converters["USVString"]
const webidlConvertersBodyInitDomString =
webidl.converters["BodyInit_DOMString?"];
const webidlConvertersUSVString = webidl.converters["USVString"];
const webidlConvertersUnsignedShort = webidl.converters["unsigned short"];
const webidlConvertersAny = webidl.converters["any"];
const webidlConvertersByteString = webidl.converters["ByteString"];
const webidlConvertersHeadersInit = webidl.converters["HeadersInit"]
const webidlConvertersHeadersInit = webidl.converters["HeadersInit"];

/**
* @typedef InnerResponse
Expand Down Expand Up @@ -233,7 +234,6 @@ function initializeAResponse(response, init, bodyWithType) {
}
}


class Response {
get [_mimeType]() {
const values = getDecodeSplitHeader(
Expand Down Expand Up @@ -452,47 +452,49 @@ webidl.converters["Response"] = webidl.createInterfaceConverter(
"Response",
ResponsePrototype,
);
const webidlConvertersResponseInit = webidl.converters["ResponseInit"] = webidl.createDictionaryConverter(
"ResponseInit",
[{
key: "status",
defaultValue: 200,
converter: webidlConvertersUnsignedShort,
}, {
key: "statusText",
defaultValue: "",
converter: webidlConvertersByteString,
}, {
key: "headers",
converter: webidlConvertersHeadersInit,
}],
);
const webidlConvertersResponseInitFast = webidl.converters["ResponseInit_fast"] = function (
init,
prefix,
context,
opts,
) {
if (init === undefined || init === null) {
return { status: 200, statusText: "", headers: undefined };
}
// Fast path, if not a proxy
if (typeof init === "object" && !core.isProxy(init)) {
// Not a proxy fast path
const status = init.status !== undefined
? webidlConvertersUnsignedShort(init.status)
: 200;
const statusText = init.statusText !== undefined
? webidlConvertersByteString(init.statusText)
: "";
const headers = init.headers !== undefined
? webidlConvertersHeadersInit(init.headers)
: undefined;
return { status, statusText, headers };
}
// Slow default path
return webidlConvertersResponseInit(init, prefix, context, opts);
};
const webidlConvertersResponseInit = webidl.converters["ResponseInit"] = webidl
.createDictionaryConverter(
"ResponseInit",
[{
key: "status",
defaultValue: 200,
converter: webidlConvertersUnsignedShort,
}, {
key: "statusText",
defaultValue: "",
converter: webidlConvertersByteString,
}, {
key: "headers",
converter: webidlConvertersHeadersInit,
}],
);
const webidlConvertersResponseInitFast = webidl
.converters["ResponseInit_fast"] = function (
init,
prefix,
context,
opts,
) {
if (init === undefined || init === null) {
return { status: 200, statusText: "", headers: undefined };
}
// Fast path, if not a proxy
if (typeof init === "object" && !core.isProxy(init)) {
// Not a proxy fast path
const status = init.status !== undefined
? webidlConvertersUnsignedShort(init.status)
: 200;
const statusText = init.statusText !== undefined
? webidlConvertersByteString(init.statusText)
: "";
const headers = init.headers !== undefined
? webidlConvertersHeadersInit(init.headers)
: undefined;
return { status, statusText, headers };
}
// Slow default path
return webidlConvertersResponseInit(init, prefix, context, opts);
};

/**
* @param {Response} response
Expand Down