-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: generator performance optimization work (#380)
- Loading branch information
1 parent
e9016ae
commit db9571c
Showing
26 changed files
with
948 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,5 @@ | ||
import { FetchFn, wrapWithRetry } from "./fetch-common.js"; | ||
import { WrappedFetch, wrappedFetch } from "./fetch-common.js"; | ||
|
||
// Browser native fetch doesn't deal well with high contention | ||
// restrict in-flight fetches to a pool of 100 | ||
let p = []; | ||
let c = 0; | ||
function pushFetchPool() { | ||
if (++c > 100) return new Promise((r) => p.push(r)); | ||
} | ||
function popFetchPool() { | ||
c--; | ||
if (p.length) p.shift()(); | ||
} | ||
|
||
export const fetch: FetchFn = wrapWithRetry(async function fetch(url, opts) { | ||
const poolQueue = pushFetchPool(); | ||
if (poolQueue) await poolQueue; | ||
try { | ||
return await globalThis.fetch(url as any, opts); | ||
} catch (e) { | ||
// CORS errors throw a fetch type error | ||
// Instead, treat this as an actual unauthorized response | ||
if (e instanceof TypeError) { | ||
return { | ||
status: 401, | ||
async text() { | ||
return ""; | ||
}, | ||
async json() { | ||
throw new Error("Not JSON"); | ||
}, | ||
arrayBuffer() { | ||
return new ArrayBuffer(0); | ||
}, | ||
}; | ||
} | ||
} finally { | ||
popFetchPool(); | ||
} | ||
}); | ||
export const fetch: WrappedFetch = wrappedFetch(globalThis.fetch); | ||
|
||
export const clearCache = () => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.