Skip to content

perf: use BTreeMap::range() and incremental memory tracking in reassembly #11

@Zious11

Description

@Zious11

Summary

Performance improvements for the TCP reassembly engine identified during PR #10 review.

Items

  1. 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.
  2. Maintain buffered_bytes incrementally in FlowDirection instead of O(n) summation per insert (segment.rs:62).
  3. 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

  • Overlap detection uses range(candidate_start..new_end)
  • FlowDirection tracks buffered_bytes as a running counter
  • total_memory updated incrementally on insert/flush/remove
  • No performance regression in existing tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions