Skip to content

refactor: build the DIAL LOCATION rewrite in a reusable scratch buffer - #67

Merged
sbogomolov merged 1 commit into
mainfrom
dial/rewrite-scratch-buffer
Aug 8, 2026
Merged

refactor: build the DIAL LOCATION rewrite in a reusable scratch buffer#67
sbogomolov merged 1 commit into
mainfrom
dial/rewrite-scratch-buffer

Conversation

@sbogomolov

Copy link
Copy Markdown
Owner

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.

DialRewrite carries 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).

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.
@sbogomolov sbogomolov self-assigned this Aug 8, 2026
@sbogomolov
sbogomolov merged commit 62f7cbc into main Aug 8, 2026
17 checks passed
@sbogomolov
sbogomolov deleted the dial/rewrite-scratch-buffer branch August 8, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant