Send SV2 frames in a single write#1771
Merged
Merged
Conversation
The encrypted header and payload were sent as two writes, so every frame left as two TCP segments. Build them into one buffer and send once, so a frame is a single segment — drops SV2 submit response time further (8.1 to 5.4 ms measured) on top of the TCP_NODELAY fix.
Test Results 2 files 2 suites 0s ⏱️ Results for commit 46d4e3e. |
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.
SV2 frames were sent as two writes — the encrypted header, then the encrypted payload — so every share submit left the device as two TCP segments. This builds both parts into one buffer and sends them in a single write, so a frame goes out as one segment.
On my hardware this drops the SV2 submit response time from ~8.1 ms to ~5.4 ms, on top of the TCP_NODELAY fix — so the two-write pattern still had measurable overhead even with Nagle disabled.
It also removes the root cause that #1722 (TCP_NODELAY) worked around: that latency came from the second segment being held back by Nagle until the first was ACKed. With the whole frame sent as a single segment there is no held-back second segment, so TCP_NODELAY is no longer needed as a fix here. It does not hurt to keep it in either — still sensible for a latency-sensitive socket — so this PR leaves it untouched.
The bytes on the wire are identical (header and payload use separate Noise nonces but are just consecutive bytes); the receiver reads the 22-byte header first and then the payload, so it is unaffected. No pool-side change needed.
Tested on hardware against an SV2 pool.