You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(mux-h2): replace loona-hpack with a sans-io HPACK module in sozu-lib #1616
sozu-lib delegates HPACK (RFC 7541) to loona-hpack 0.4.3. The crate has not changed since 2024-11-03 (bearcove/loona), and its decoder allocates on the hot path:
every Huffman-coded string builds a fresh HuffmanDecoder (decoder.rs:148), which is a HashMap of 257 entries rebuilt from the code table (huffman.rs:58-81), then decodes into a new Vec<u8>;
every entry inserted into the dynamic table is two owned Vec<u8> in a VecDeque.
Measurement
Release build, one worker, LD_PRELOAD allocation counter, 20 HTTPS H2 requests with one connection each, allocations grouped by their first sozu frames: the Huffman decoder setup alone costs about 124 allocations and 23 KiB per H2 connection, i.e. 37 % of the H2 allocations. A browser or curl always Huffman-codes its header values, so this is paid on every request.
Plan
Replace the dependency with an HPACK module inside sozu-lib (protocol::mux::hpack), written from RFC 7541, with no I/O:
decoder over &[u8] with a per-header callback; literal strings are borrowed from the input, Huffman strings are decoded into one scratch buffer owned by the decoder and reused;
Huffman decoding through a nibble state machine whose table is computed at compile time (const), with no allocation at all;
dynamic table as one byte buffer plus one index of offsets, grown to its high-water mark and bounded by the table size, instead of two Vec<u8> per entry;
encoder writing into the caller's buffer, byte-for-byte the same representation policy as today;
guards: SETTINGS_HEADER_TABLE_SIZE bound on size updates, size updates only at the start of a block, integer overflow, index out of table, Huffman padding longer than 7 bits or not all ones, EOS inside a string;
tests: RFC 7541 Appendix C.2 to C.6 in decoding and encoding, quickcheck round trips, one test per malformed input and its error, allocation criteria with test_allocations (0 allocation for a steady-state block and for Huffman decoding); the fuzz target moves to the new decoder;
remove loona-hpack from Cargo.toml, lib/Cargo.toml, fuzz/Cargo.toml and both lock files; no new dependency;
measure allocations and syscalls end to end before and after, H2 one connection per request and H2 multiplexed.
Activity
perf(mux-h2): replace loona-hpack with a sans-io HPACK module (#1620)