1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -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:
Aaron O'Mullan 2021-09-27 13:19:24 +02:00 committed by GitHub
parent ff3a17b72d
commit 9167f0c6bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -67,11 +67,12 @@
* @param {string} url
* @param {[string, string][]} headerList
* @param {typeof __window.bootstrap.fetchBody.InnerBody} body
* @param {boolean} maybeBlob
* @returns
*/
function newInnerRequest(method, url, headerList = [], body = null) {
function newInnerRequest(method, url, headerList, body, maybeBlob) {
let blobUrlEntry = null;
if (url.startsWith("blob:")) {
if (maybeBlob && url.startsWith("blob:")) {
blobUrlEntry = blobFromObjectUrl(url);
}
return {
@ -236,7 +237,7 @@
// 5.
if (typeof input === "string") {
const parsedURL = new URL(input, baseURL);
request = newInnerRequest("GET", parsedURL.href, [], null);
request = newInnerRequest("GET", parsedURL.href, [], null, true);
} else { // 6.
if (!(input instanceof Request)) throw new TypeError("Unreachable");
request = input[_request];

View file

@ -103,6 +103,7 @@
url,
headersList,
body !== null ? new InnerBody(body) : null,
false,
);
const signal = abortSignal.newSignal();
const request = fromInnerRequest(innerRequest, signal, "immutable");