refactor: build the DIAL LOCATION rewrite in a reusable scratch buffer - #67
Merged
Conversation
The rewrite allocated a fresh ~4 KiB string per rewritten datagram, on the packet path. Build into a scratch reserved once to MAX_UDP_PAYLOAD_SIZE instead, and compute the rewritten size up front so the overflow check needs no copy and the splice cannot reallocate. DialRewrite now carries a view into that scratch; both callers send it before returning.
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.
The LOCATION rewrite allocated a fresh ~4 KiB string per rewritten datagram, on the packet path. It now builds into a scratch reserved once to
MAX_UDP_PAYLOAD_SIZE.The rewritten size is computed up front from the payload length, the spliced span and the formatted authority, so the overflow check rejects without copying and the splice that follows fits the reserved scratch by construction — the previous order built the string first, which in the overflow case would have reallocated past the reserve, exactly where it matters. The authority itself is formatted into a stack array, so the replacement text doesn't allocate either.
DialRewritecarries a view into the scratch; both callers send it before returning.Native (889), docker/Linux (876) and e2e (33 cases) green. The new test covers the reused buffer's real risk — a stale tail from a longer predecessor — and was verified to fail when the reset is suppressed, while the other DIAL rewrite tests still pass (their payloads are similar lengths).