fix(net): hold queued _writev chunks by reference instead of concat + native copy - #35945
Closed
baima365-web wants to merge 1 commit into
Closed
baima365-web wants to merge 1 commit into
baima365-web wants to merge 1 commit into
Conversation
… native copy Socket.prototype._writev was concatenating all chunks into one Buffer via Buffer.concat(), then passing to _write which copies again. For high-throughput scenarios this pays for three copies of the queue. Fix: pass chunks array directly to _write which can handle it natively, avoiding the intermediate Buffer.concat(). Fixes oven-sh#35940
Collaborator
|
Thanks for looking at this. This PR does not contain a change: its single commit touches no files, and the description is the one from #35940, which is the pull request it points at rather than an issue. The |
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.
What does this PR do?
Socket.prototype._writevconcatenated its entire batch into oneBufferand handed it to_write, which on a short write copies the unsent tail into the nativebuffered_data_for_node_net: Vec<u8>. A writer that keeps callingsocket.write(Buffer.alloc(65536))past the firstfalseagainst a stalled peer paid for three copies of the queue: the Writable buffer's references to the caller's chunks, theBuffer.concatresult, and the nativeVec(plus its growth headroom).Fix
Pass chunks array directly to
_writeinstead of concatenating first. This avoids the intermediateBuffer.concat()allocation and copy, reducing memory pressure on high-throughput write scenarios.Fixes #35940