Skip to content

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

@obchain

Description

@obchain

Where

src/network/dpi/quic.rs:370-371

let dcid = payload[offset..offset + dcid_len].to_vec();
quic_info.connection_id = dcid.clone();
quic_info.connection_id_hex = None;
offset += dcid_len;

What

The long-header QUIC parser allocates the DCID bytes into a Vec<u8>, then clones that Vec into quic_info.connection_id, and only later passes &dcid to extract_tls_from_long_header_packet. The second to_vec/clone round-trip allocates a duplicate Vec for every long-header QUIC packet parsed.

The short-header path had the exact same shape and was fixed in #317 (commit b4a8…). The long-header path was missed.

Why it matters

QUIC initial-packet parsing is on the DPI hot path for every QUIC flow (HTTP/3, increasing share of web traffic). The DCID size varies by deployment but commonly 8-20 bytes; the wasted allocation is small per packet, large in aggregate.

Suggested fix

Drop the intermediate let dcid = …to_vec() and assign quic_info.connection_id directly from the payload slice. Capture the dcid byte-range and pass &payload[dcid_range] to extract_tls_from_long_header_packet — no separate Vec needed since the function takes dcid: &[u8].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions