Repository navigation
Conversation
Signed-off-by: Tjerk Meesters <tmeesters@zendesk.com>
datibbaw
force-pushed
the
borrowed-header-map-decoding
branch
from
November 3, 2026 02:22
85e138c to
80a604a
Compare
datibbaw
marked this pull request as ready for review
November 3, 2026 02:42
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.
Bulk header-map reads currently copy each name and value into separate allocations after the host has transferred the serialized buffer into guest memory. This adds
hostcalls::get_serialized_mapand an owningmap::SerializedMapso callers can keep that buffer and borrow its fields.The Go SDK already uses shared-buffer views for bulk map decoding. Its
DeserializeMapallocates the result slice, then constructs names and values as string views into the serialized buffer. For example, the value decoding uses:That path still allocates the pair slice and requires the initial host-to-guest transfer, but avoids separate allocations and copies for each field. This PR applies the same shared-buffer approach in Rust, with an explicit buffer owner and compiler-checked lifetimes rather than unsafe string conversions. Values stay available as bytes; callers opt into text validation when needed.
For example, acquiring and decoding 20 header pairs currently takes approximately 42 allocations:
With borrowed values those allocations drop to just the first two. Callers only make copies to e.g. retain values for asynchronous work.
pairs()returns borrowed(&str, &[u8])entries, preserving opaque values without UTF-8 validation.text_pairs()additionally validates values as UTF-8.The new hostcall returns host statuses unchanged and rejects a null pointer with nonzero length as
InternalFailure. The initial host-to-guest transfer remains; this removes subsequent per-field copies within the guest.Tests cover:
Allocation tests assert two allocations for acquisition, always, plus byte-valued views at 1, 4, 20, and 64 entries over repeated acquisition/drop cycles.