perf(dpi/quic): drop redundant dcid.clone() in long-header parser#343
Open
obchain wants to merge 1 commit into
Open
perf(dpi/quic): drop redundant dcid.clone() in long-header parser#343obchain wants to merge 1 commit into
dcid.clone() in long-header parser#343obchain wants to merge 1 commit into
Conversation
`parse_long_header_packet_with_length` was allocating the DCID bytes twice per packet: let dcid = payload[offset..offset + dcid_len].to_vec(); quic_info.connection_id = dcid.clone(); ... extract_tls_from_long_header_packet(packet_data, &mut quic_info, &dcid, ...); The intermediate `dcid` Vec only existed to feed `extract_tls_*` a `&[u8]`, and `extract_tls_*` already accepts a borrowed slice — there's no reason to materialize a second owned copy when the bytes are sitting right there inside `payload`. Capture the DCID byte-range, assign `quic_info.connection_id` directly from `payload[dcid_range]`, and reborrow the same slice for the `extract_tls_*` call. The borrow checker is fine with this since `payload: &[u8]` and the `&mut QuicInfo` reference disjoint memory. The short-header path had the same shape and got fixed in domcyrus#317. The long-header path was missed; this brings the two paths into parity. No behavior change — the 11 QUIC DPI unit tests plus the full lib sweep (371 passed) keep their existing assertions. Closes domcyrus#342
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.
Summary
parse_long_header_packet_with_lengthwas allocating the DCID bytes twice per packet:The intermediate
dcidVeconly existed to feedextract_tls_*a&[u8], and that function already accepts a borrowed slice — no reason to materialize a second owned copy when the bytes are sitting inpayload.This change captures the DCID byte-range, assigns
quic_info.connection_iddirectly frompayload[dcid_range], and reborrows the same slice for theextract_tls_*call. The borrow checker is fine with this —payload: &[u8]and the&mut QuicInforeference disjoint memory.The short-header path had the same shape and was fixed in #317; the long-header path was missed. This brings the two paths into parity.
Closes #342.
Behavior
No change.
quic_info.connection_idends up holding the same bytes;extract_tls_*receives the same DCID slice it did before. Verified by:Test plan
cargo test --libcargo fmt --checkcargo clippy --all-targets -- -D warnings