Repository navigation
perf(client): borrow request headers when nothing is merged; no copy into the request target - #9
Merged
casibbald merged 1 commit intoOct 27, 2026
Conversation
…ge; no copy into the request target - `prepare_attempt_headers` rebuilt a merged `HeaderMap` for every attempt: defaults, then provider metadata, then the request's headers, each value cloned. With no default headers, no metadata provider and nothing to strip (the common case), the request's own map is used as is (`Cow::Borrowed`). That saves the map's allocations and a clone of every value; the first clone of a value built with `HeaderValue::from_str` allocates, because it promotes the bytes to shared. - `origin_form` built the request target in a `String` and then `parse()` copied it into the `Uri`. `Uri::try_from(String)` takes the buffer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y3TSRmEZAYU6RBUXhkn7WF
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
Two allocation cuts in the pooled
Client's request path:prepare_attempt_headersreturnsCow<HeaderMap>. With no default headers, no metadata provider and no credentials to strip (the common case), the request's own map is used as is, instead of building a merged copy and cloning every value per attempt.origin_formhands itsStringtoUri::try_frominstead ofparse(), which copied it.Behaviour is unchanged: when there is anything to merge or strip, the merged map is built as before.
Numbers
examples/bench_client pool, 16 coroutines, 2000 requests each, againstexamples/bench_serveron loopback (ms02), three rounds. Allocations per request are deterministic; req/s moved with host load (18 to 25) and is within noise.Tests
cargo fmt --check, clippy (default and all features, all targets), and the full suite with all features (310 passed) and with default features, on Rust 1.99.0.🤖 Generated with Claude Code
https://claude.ai/code/session_01Y3TSRmEZAYU6RBUXhkn7WF