mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
perf(fetch): optimize newInnerRequest blob url check (#12245)
Avoid "blob:" prefix check on requests built in the http module since those can never be blob objects Reduces cost of `newInnerRequest()` from 20ms to 0.1ms in my profiled run on ~2.5M reqs
This commit is contained in:
parent
ff3a17b72d
commit
9167f0c6bd
2 changed files with 5 additions and 3 deletions
|
@ -67,11 +67,12 @@
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
* @param {[string, string][]} headerList
|
* @param {[string, string][]} headerList
|
||||||
* @param {typeof __window.bootstrap.fetchBody.InnerBody} body
|
* @param {typeof __window.bootstrap.fetchBody.InnerBody} body
|
||||||
|
* @param {boolean} maybeBlob
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function newInnerRequest(method, url, headerList = [], body = null) {
|
function newInnerRequest(method, url, headerList, body, maybeBlob) {
|
||||||
let blobUrlEntry = null;
|
let blobUrlEntry = null;
|
||||||
if (url.startsWith("blob:")) {
|
if (maybeBlob && url.startsWith("blob:")) {
|
||||||
blobUrlEntry = blobFromObjectUrl(url);
|
blobUrlEntry = blobFromObjectUrl(url);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
@ -236,7 +237,7 @@
|
||||||
// 5.
|
// 5.
|
||||||
if (typeof input === "string") {
|
if (typeof input === "string") {
|
||||||
const parsedURL = new URL(input, baseURL);
|
const parsedURL = new URL(input, baseURL);
|
||||||
request = newInnerRequest("GET", parsedURL.href, [], null);
|
request = newInnerRequest("GET", parsedURL.href, [], null, true);
|
||||||
} else { // 6.
|
} else { // 6.
|
||||||
if (!(input instanceof Request)) throw new TypeError("Unreachable");
|
if (!(input instanceof Request)) throw new TypeError("Unreachable");
|
||||||
request = input[_request];
|
request = input[_request];
|
||||||
|
|
|
@ -103,6 +103,7 @@
|
||||||
url,
|
url,
|
||||||
headersList,
|
headersList,
|
||||||
body !== null ? new InnerBody(body) : null,
|
body !== null ? new InnerBody(body) : null,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
const signal = abortSignal.newSignal();
|
const signal = abortSignal.newSignal();
|
||||||
const request = fromInnerRequest(innerRequest, signal, "immutable");
|
const request = fromInnerRequest(innerRequest, signal, "immutable");
|
||||||
|
|
Loading…
Reference in a new issue