perf(fetch): skip empty ResponseInit work and send buffered bodies directly - #5702
Open
anonrig wants to merge 3 commits into
Open
perf(fetch): skip empty ResponseInit work and send buffered bodies directly#5702anonrig wants to merge 3 commits into
anonrig wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5702 +/- ##
==========================================
- Coverage 93.47% 93.47% -0.01%
==========================================
Files 110 110
Lines 38846 38929 +83
==========================================
+ Hits 36310 36387 +77
- Misses 2536 2542 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
anonrig
force-pushed
the
cursor/fetch-response-init-buffered-body-7afe
branch
2 times, most recently
from
August 18, 2026 18:06
f550e4a to
fc09325
Compare
…rectly ResponseInit defaults status/statusText, so every new Response() ran WebIDL conversion and reason-phrase validation for values makeResponse() already has. extractBody() already keeps string/BufferSource bodies on `source`, but http-network-fetch still teed the companion Web Stream and incrementally read it. Send those bytes to the dispatcher instead. Start H1 idle-socket validation when the socket becomes idle so the GHSA-35p6-xmwp-9g52 event-loop yield overlaps body consumption instead of gating the next dispatch. Assisted by Cursor Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Arming idle-socket validation on message-complete set kIdleSocketValidation to 1, so Client.busy() was true while no request was waiting. BalancedPool then skipped that upstream and weighted-round-robin ratios drifted (CI cases 5, 6, 9). Start the poll-yield timer in the background and only block the socket once a request is actually queued. Assisted by Cursor Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Codecov flagged 11 untested lines in the string/Uint8Array dispatch fast path — fetch() never sets processRequestEndOfBody. Exercise both source types through fetching() and send a Uint8Array POST through the public API. Assisted by Cursor Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
anonrig
force-pushed
the
cursor/fetch-response-init-buffered-body-7afe
branch
from
August 18, 2026 18:45
fc09325 to
c75d899
Compare
mcollina
requested changes
Aug 21, 2026
mcollina
left a comment
Member
There was a problem hiding this comment.
Can you please split the changes to client-h1 from the fetch ones?
| // Block further writes on this socket until the poll yield completes. | ||
| socket[kIdleSocketValidation] = 1 | ||
| armIdleSocketValidation(client, socket) | ||
| } |
Member
There was a problem hiding this comment.
Can you send the changes to this as a separate PR?
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This relates to...
Rationale
#5701skipped Request constructor work whenRequestInitwas empty (dictionary defaults were making everyfetch(url)look non-empty) and dropped the idle-socketsetTimeout(0)floor.This PR applies the same ideas to the next similar hot paths, independently of that branch:
ResponseInitdefaults —status: 200andstatusText: ""meant everynew Response()/new Response(body)ran WebIDL conversion and reason-phrase validation for valuesmakeResponse()already has.extractBody()already keeps string /BufferSourcebodies onsource, but HTTP-network-fetch still teed the companion Web Stream and incrementally read it before handing bytes to the dispatcher.Changes
ResponseInitfields, not WebIDL defaults. Omitted /{}init skips conversion;makeResponse()already supplies 200 /"".request.body.sourceis a string orUint8Array, clone headers only (no stream tee) and passsourcetoagent.dispatch.onMessageCompletewhenkSocketUsedbecomes true. The existing write-timeclearIdleSocketValidationand poisoning checks are unchanged.Features
N/A
Bug Fixes
N/A
Breaking Changes and Depreciations
N/A
Benchmarks
Loopback, Node 22.14. Measured against
main(e609acb0):new Response()new Response(null, { status: 201 })fetchPOST string body p50fetch().text()p50The GET keep-alive number is still dominated by
setTimeout(0)onmain; #5701 replaces that withsetImmediate. Starting validation at idle is complementary once that lands.Status