Summary
quic::connection_id_to_hex (src/network/dpi/quic.rs:1881-1886) renders a QUIC connection ID to a colon-separated lowercase hex string via the worst-case allocation pattern:
fn connection_id_to_hex(id: &[u8]) -> String {
id.iter()
.map(|b| format!("{:02x}", b))
.collect::<Vec<String>>()
.join(":")
}
Each byte goes through format!("{:02x}", b), allocating a 2-byte String. The whole iterator then collects into a Vec<String> (one more heap allocation), and join(":") finally walks the vector to build the result String. For an 8-byte connection ID (common short form) that is 8 String allocations + 1 Vec allocation + 1 final String allocation per render.
Evidence
- Helper definition:
src/network/dpi/quic.rs:1881-1886
- Helper is invoked when rendering
QuicInfo.connection_id for the UI.
Proposed fix
Replace with a single accumulator String::with_capacity(id.len() * 3) (2*N hex + N-1 separators), iterating bytes and using write!(buf, "{b:02x}") (writing to an in-place String does not allocate when capacity is reserved), inserting ':' between bytes. One allocation per call, output byte-for-byte identical.
Happy to open a PR with a regression test that locks the existing aa:bb:cc:dd lowercase-with-colon format.
Summary
quic::connection_id_to_hex(src/network/dpi/quic.rs:1881-1886) renders a QUIC connection ID to a colon-separated lowercase hex string via the worst-case allocation pattern:Each byte goes through
format!("{:02x}", b), allocating a 2-byteString. The whole iterator then collects into aVec<String>(one more heap allocation), andjoin(":")finally walks the vector to build the resultString. For an 8-byte connection ID (common short form) that is 8Stringallocations + 1Vecallocation + 1 finalStringallocation per render.Evidence
src/network/dpi/quic.rs:1881-1886QuicInfo.connection_idfor the UI.Proposed fix
Replace with a single accumulator
String::with_capacity(id.len() * 3)(2*Nhex +N-1separators), iterating bytes and usingwrite!(buf, "{b:02x}")(writing to an in-placeStringdoes not allocate when capacity is reserved), inserting':'between bytes. One allocation per call, output byte-for-byte identical.Happy to open a PR with a regression test that locks the existing
aa:bb:cc:ddlowercase-with-colon format.