Skip to content

perf(dpi/quic): drop redundant dcid.clone() in long-header parser#343

Open
obchain wants to merge 1 commit into
domcyrus:mainfrom
obchain:perf/quic-long-header-drop-dcid-clone
Open

perf(dpi/quic): drop redundant dcid.clone() in long-header parser#343
obchain wants to merge 1 commit into
domcyrus:mainfrom
obchain:perf/quic-long-header-drop-dcid-clone

Conversation

@obchain
Copy link
Copy Markdown
Contributor

@obchain obchain commented May 28, 2026

Summary

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 that function already accepts a borrowed slice — no reason to materialize a second owned copy when the bytes are sitting in payload.

This change captures the DCID byte-range, assigns quic_info.connection_id directly from payload[dcid_range], and reborrows the same slice for the extract_tls_* call. The borrow checker is fine with this — payload: &[u8] and the &mut QuicInfo reference 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_id ends up holding the same bytes; extract_tls_* receives the same DCID slice it did before. Verified by:

cargo test --lib network::dpi::quic   # 11 passed
cargo test --lib                       # 371 passed
cargo fmt --check                      # clean
cargo clippy --all-targets -- -D warnings  # clean

Test plan

  • All QUIC DPI unit tests pass
  • Full cargo test --lib
  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings

`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
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.

perf(dpi/quic): drop redundant dcid.clone() in parse_long_header_packet_with_length

1 participant