-
Notifications
You must be signed in to change notification settings - Fork 55
perf: reduce Response.clone() overhead in tiered cache #1090
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,9 +44,14 @@ export function createTieredCache( | |||||||||||||||||||||||||||||||||||||||||||
| request: RequestInfo | URL, | ||||||||||||||||||||||||||||||||||||||||||||
| matched: Response, | ||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||
| const body = await matched.arrayBuffer(); | ||||||||||||||||||||||||||||||||||||||||||||
| const headers = matched.headers; | ||||||||||||||||||||||||||||||||||||||||||||
| await Promise.all( | ||||||||||||||||||||||||||||||||||||||||||||
| indexOfCachesToUpdate.map((index) => | ||||||||||||||||||||||||||||||||||||||||||||
| openedCaches[index].put(request, matched.clone()) | ||||||||||||||||||||||||||||||||||||||||||||
| openedCaches[index].put( | ||||||||||||||||||||||||||||||||||||||||||||
| request, | ||||||||||||||||||||||||||||||||||||||||||||
| new Response(body.slice(0), { headers }), | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The new Response created for cache tiers omits Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The same defect is present in the 🐛 Proposed fix – preserve status and statusText- const body = await matched.arrayBuffer();
- const headers = matched.headers;
+ const body = await matched.arrayBuffer();
+ const { status, statusText, headers } = matched;
await Promise.all(
indexOfCachesToUpdate.map((index) =>
openedCaches[index].put(
request,
- new Response(body.slice(0), { headers }),
+ new Response(body.slice(0), { status, statusText, headers }),
)
),
);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -123,8 +128,13 @@ export function createTieredCache( | |||||||||||||||||||||||||||||||||||||||||||
| request: RequestInfo | URL, | ||||||||||||||||||||||||||||||||||||||||||||
| response: Response, | ||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<void> => { | ||||||||||||||||||||||||||||||||||||||||||||
| const putPromises = openedCaches.map((caches) => | ||||||||||||||||||||||||||||||||||||||||||||
| caches.put(request, response.clone()) | ||||||||||||||||||||||||||||||||||||||||||||
| const body = await response.arrayBuffer(); | ||||||||||||||||||||||||||||||||||||||||||||
| const headers = response.headers; | ||||||||||||||||||||||||||||||||||||||||||||
| const putPromises = openedCaches.map((cache) => | ||||||||||||||||||||||||||||||||||||||||||||
| cache.put( | ||||||||||||||||||||||||||||||||||||||||||||
| request, | ||||||||||||||||||||||||||||||||||||||||||||
| new Response(body.slice(0), { headers }), | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+131
to
138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🐛 Proposed fix- const body = await response.arrayBuffer();
- const headers = response.headers;
- const putPromises = openedCaches.map((cache) =>
- cache.put(
- request,
- new Response(body.slice(0), { headers }),
- )
- );
+ const body = await response.arrayBuffer();
+ const { status, statusText, headers } = response;
+ const putPromises = openedCaches.map((cache) =>
+ cache.put(
+ request,
+ new Response(body.slice(0), { status, statusText, headers }),
+ )
+ );📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| await Promise.all(putPromises); | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Reading
matched.arrayBuffer()consumes the response body, so thematchedresponse returned frommatch()will be unusable. Consider returning a new Response built from the buffered body (and using that for cache updates) or otherwise avoid consuming the response that is returned to callers.Prompt for AI agents