http: improve performance for end() with known-length string #65466
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 415 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.361
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #65466"
general
weight: 0.35
efekrskl
When you call
end(data)on an outgoing HTTP request, we previously wrote the data, and then ran_send('', ...)just to trigger flushing the headers, which resulted in an extra zero-byte write call and bonus nextTick before'finish'.When the length is known and
content-lengthis used (not chunking, so we don't need a terminator) we can skip this completely: prep the content-length header explicitly, and combine the finish into the existing write step.This drops a nextTick, and goes from 2 write calls to 1 for the very common case of
response.end(data)with a string, and for buffer data goes from 3 writes to 2.In practice, in the tiny benchmark here which I think represents a very common use case (small API responses) I see this boosting HTTP RPS by up to 9% for writes up to 1KB or so. For larger responses the response write time starts to outweigh this, but I still see 3% RPS boost at 16KB. Needs autocannon to hit the rates required, you can test yourself with:
Added a new test confirming the specific details and edge cases this touches, and updated one existing test which specifically asserted that
end(data)triggered two writes, including the empty one.<!--
If you are submitting a pull request for the first time,
check out the guide for first-time contributors for tips and answers to FAQs:
https://github.com/nodejs/node/blob/HEAD/doc/contributing/first-contributions.md
Before submitting a pull request, please read:
https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines
For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that
make -j4 test(UNIX), orvcbuild test(Windows) passes.If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the
notable-changelabel.Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
-->