refactor(ui/details): single-allocation hex render for STUN Transaction ID#328
refactor(ui/details): single-allocation hex render for STUN Transaction ID#328Pablosinyores wants to merge 1 commit into
Conversation
…on ID
Detail panel built the STUN Transaction-ID display string with
info.transaction_id.iter().map(|b| format!("{:02x}", b)).collect::<String>()
That yields 13 heap allocations per render: one short String per byte
across the 12-byte RFC 5389 transaction ID, plus the final String into
which they're collected.
Rewrite to `String::with_capacity(bytes.len() * 2)` + `write!` per byte:
- One allocation, sized exactly (2 hex chars per byte).
- write!-to-String is infallible; result discarded with `let _`.
- Same observable hex output (lowercase, zero-padded, no separators).
Matches the merged single-alloc hex pattern from
575ed75 refactor(dpi/bittorrent): single-allocation hex_encode for
info-hash render (domcyrus#307), applied to the parallel UI render path.
No behavior, layout, or copy change. cargo test --lib 365/365.
|
Hi @Pablosinyores, thanks for the PR and welcome to RustNet! The change is correct and clean: the capacity hint is exact, the import is right, and the output is identical to before. Two pointers from CONTRIBUTING.md on how we weigh changes like this:
None of this is a knock on the code. If you want to dig into allocation work, profiling with PROFILING.md to find a genuinely hot path is the best place to start. Thanks again, and please keep them coming! |
Summary
Detail panel rendered the STUN Transaction-ID display string with
which yields 13 heap allocations per render: one short `String` per byte across the 12-byte RFC 5389 transaction ID, plus the final `String` into which they are collected (`src/ui/tabs/details.rs:867`).
Rewrite to a single `String::with_capacity(bytes.len() * 2)` + `write!` per byte:
Why this shape
Matches the merged single-alloc hex pattern from
applied to the parallel UI render path. `info.transaction_id` is `[u8; 12]` so the capacity hint is exact.
Test plan
No behavior, layout, or copy change.