perf(dpi/quic): use Cow<'static, str> for known QUIC version strings#401
Open
obchain wants to merge 1 commit into
Open
perf(dpi/quic): use Cow<'static, str> for known QUIC version strings#401obchain wants to merge 1 commit into
obchain wants to merge 1 commit into
Conversation
QuicInfo::new() is called on every QUIC long-header packet. The internal quic_version_to_string helper returned Option<String>, allocating a heap String for each of the seven well-known version identifiers (v1, v2, draft-27/28/29, Q050, T050) even though they are compile-time constants. Change the field type to Option<Cow<'static, str>> and return Cow::Borrowed for the static arms, Cow::Owned only for the dynamic draft-N case. Cow::clone() for a Borrowed variant is a pointer copy, so the merge-path clone becomes cheaper too. The one display callsite in details.rs changes from .as_ref() + .clone() to .as_deref() + .to_owned(), which is semantically identical. A unit test asserts the Borrowed invariant for all seven known versions and verifies the Owned path for the dynamic draft-N arm. Closes domcyrus#400
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.
Closes #400
What
QuicInfo::new(version)is called on every QUIC long-header packet. The internalquic_version_to_stringhelper returnedOption<String>, allocating a heapStringfor each of the seven well-known version identifiers (v1,v2,draft-27/28/29,Q050,T050) — even though they are compile-time constants.This PR changes
QuicInfo.version_stringfromOption<String>toOption<Cow<'static, str>>and returnsCow::Borrowedfor the static arms:QuicInfoderives onlyDebug + Clone, so the field-type change requires no serde or macro adjustments.Cow::clone()for aBorrowedvariant is a pointer copy, so the merge-path clone also becomes cheaper.The single display callsite in
details.rschanges from.as_ref()+.clone()to.as_deref()+.to_owned(), which is semantically identical.Test
A new unit test
quic_version_string_known_versions_are_borrowedasserts:Cow::Borrowed— enforcing the no-alloc guarantee at the type level.None.draft-Narm producesCow::Ownedwith the correct label.Impact
Per QUIC long-header packet with a known version: −1 heap allocation. Under sustained HTTP/3 traffic (QUIC v1) this path is hot — every packet avoids a small-string allocation and its associated allocator overhead.
Verification