diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-09-27 13:19:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 13:19:24 +0200 |
commit | 9167f0c6bda44846a9c54712ae64d05383bdfc3e (patch) | |
tree | 57819236b8346f3b096c2a5417942049ec8fccb5 /ext/fetch/23_request.js | |
parent | ff3a17b72d7e10db4a0ca68afbf2d40bf280431c (diff) |
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
Diffstat (limited to 'ext/fetch/23_request.js')
-rw-r--r-- | ext/fetch/23_request.js | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js index bf1683b35..845e47877 100644 --- a/ext/fetch/23_request.js +++ b/ext/fetch/23_request.js @@ -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]; |