Summary
Performance improvements for the TCP reassembly engine identified during PR #10 review.
Items
- Use
BTreeMap::range() for overlap detection instead of iterating all segments (segment.rs:85). Only examine segments that could overlap with the new segment's range.
- Maintain
buffered_bytes incrementally in FlowDirection instead of O(n) summation per insert (segment.rs:62).
- Maintain
total_memory incrementally instead of update_memory() O(n) recomputation across all flows (mod.rs:379).
Impact
Current approach is O(n) per packet per flow for memory tracking and O(n) for overlap scan. With max_segments=10K, this is bounded but wasteful. Incremental tracking makes all three O(1).
Acceptance Criteria
Summary
Performance improvements for the TCP reassembly engine identified during PR #10 review.
Items
BTreeMap::range()for overlap detection instead of iterating all segments (segment.rs:85). Only examine segments that could overlap with the new segment's range.buffered_bytesincrementally in FlowDirection instead of O(n) summation per insert (segment.rs:62).total_memoryincrementally instead ofupdate_memory()O(n) recomputation across all flows (mod.rs:379).Impact
Current approach is O(n) per packet per flow for memory tracking and O(n) for overlap scan. With max_segments=10K, this is bounded but wasteful. Incremental tracking makes all three O(1).
Acceptance Criteria
range(candidate_start..new_end)FlowDirectiontracksbuffered_bytesas a running countertotal_memoryupdated incrementally on insert/flush/remove