Skip to content

perf(transport): eliminate heap allocations and HashMap churn in FecReassembler hot path - #176

Merged
tailroom merged 6 commits into
mainfrom
perf/fec-reassembler-zero-alloc
Oct 27, 2026
Merged

tailroom merged 6 commits into
mainfrom
perf/fec-reassembler-zero-alloc

Conversation

@vxfemboy

@vxfemboy vxfemboy commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Resolves #171

Summary

This PR eliminates heap allocations, per-shard HashMap lookups, and intermediate vector cloning in FecReassembler::push(), delivering zero-alloc in-place reassembly for clean-path transport and eliminating Vec<Vec<u8>> allocation during Reed-Solomon packet-loss recovery. It also updates the documentation curriculum, architectural specifications, roadmap, and changelog.

Changes

  1. Flat Pre-allocated ObjState & Systematic Slicing:
    • Replaced shards: HashMap<u16, Vec<u8>> in ObjState with a 256-bit bitset (seen_mask: [u64; 4]) and pre-allocated contiguous payload: Vec<u8>.
    • Incoming systematic source shards (idx < K) are copied directly into payload[idx * shard_len ..] with zero heap allocation.
    • Clean delivery path (source_count == K) returns the completed object via std::mem::take(&mut state.payload) and truncate(size), completely skipping RS decoding and vector stitching.
  2. In-Place RS Recovery (reconstruct_missing_sources):
    • Added decode_source_into and reconstruct_missing_sources in crates/yip-transport/src/rs.rs.
    • Parity reconstruction operates directly on missing shard slices in the pre-allocated payload buffer using a single scratch buffer, eliminating the Vec<Vec<u8>> heap matrix churn.
  3. Flat Open-Addressing ObjectTable:
    • Replaced HashMap<u64, ObjState> with ObjectTable, a flat contiguous table using SplitMix64 fast hashing and backward-shift deletion with zero tombstones and zero dynamic heap reallocations during packet ingress/eviction.
    • Pre-allocated FIFO order: VecDeque<u64> ring buffer capacity.
  4. Criterion Microbenchmarks:
    • Added benches/fec_reassemble.rs to yip-bench.
  5. Documentation, Roadmap & Changelog Sync:

Benchmark Results (Criterion)

Benchmark Scenario Baseline Optimized Speedup
fec_reassemble_clean_k1 361.98 ns 117.11 ns 3.1x faster (-67.6% latency)
fec_reassemble_clean_k3 690.73 ns 173.12 ns 4.0x faster (-74.9% latency)
fec_reassemble_loss_k3_r1 1.0401 µs 631.83 ns 1.65x faster (-39.3% latency)

Verification

  • cargo test --workspace: All 387 workspace unit tests + 98 integration tests pass cleanly.
  • cargo clippy --workspace --all-targets -- -D warnings: Clean.
  • cargo fmt --check: Clean.
  • cargo shear: Clean.

@vxfemboy
vxfemboy temporarily deployed to benchmark-approval October 26, 2026 23:58 — with GitHub Actions Inactive
@vxfemboy
vxfemboy temporarily deployed to benchmark-approval October 26, 2026 23:58 — with GitHub Actions Inactive
@vxfemboy
vxfemboy temporarily deployed to benchmark-approval October 27, 2026 00:08 — with GitHub Actions Inactive
@vxfemboy
vxfemboy temporarily deployed to benchmark-approval October 27, 2026 00:08 — with GitHub Actions Inactive
@tailroom
tailroom merged commit 92f9544 into main Oct 27, 2026
11 checks passed
@tailroom
tailroom deleted the perf/fec-reassembler-zero-alloc branch October 27, 2026 01:52

This branch was previously deployed

1 inactive deployment
benchmark-approval — aa4b59da Deployed Oct 27, 2026 by vxfemboy via benchmarks #66
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(transport): eliminate heap allocations and HashMap churn in FecReassembler hot path

2 participants