Skip to content

Comments

Improve duplicate suppression hot paths and remove redundant outbound queue scans#1774

Open
robekl wants to merge 2 commits intomeshcore-dev:devfrom
robekl:optimize
Open

Improve duplicate suppression hot paths and remove redundant outbound queue scans#1774
robekl wants to merge 2 commits intomeshcore-dev:devfrom
robekl:optimize

Conversation

@robekl
Copy link

@robekl robekl commented Feb 21, 2026

This PR applies two focused performance improvements in packet processing and scheduling paths.

What changed

1) Packet-hash caching with faster duplicate-table prefiltering

  • Packet hash computation is now cached on the packet object and reused when packet content is unchanged.
  • The cache is explicitly invalidated at mutation/reuse boundaries so duplicate checks always reflect current packet state.
  • Duplicate detection now uses small constant-size prefilters (for packet-hash prefix and ACK low-byte) to quickly reject obvious misses before any full table scan.
  • Existing exact-match duplicate checks remain in place when a prefilter indicates a possible hit.

2) Outbound scheduler no-double-scan path

  • The send loop no longer performs a separate “ready count” scan before selecting the next outbound packet.
  • Scheduling now relies on a single retrieval pass, preserving existing timing, CAD, and transmit behavior.

Why this is beneficial

  • Reduces repeated CPU work in high-frequency duplicate-suppression paths by:
    • avoiding repeat hash recomputation for unchanged packets
    • avoiding many unnecessary full duplicate-table scans
  • Reduces scheduler overhead by removing redundant linear queue traversal.
  • Keeps memory usage static and embedded-friendly with simple fixed-size structures.

Reviewer-focused implementation notes

  • Duplicate prefilters are intentionally conservative:
    • They can produce false positives (which fall through to exact checks),
    • but do not introduce false negatives for duplicate detection.
  • Hash cache correctness is maintained by explicit invalidation where packet fields are updated or packet instances are recycled.
  • Behavior is unchanged for packet matching semantics and transmit gating; this PR targets execution cost, not routing policy.

…lters

Cache packet SHA256 values on Packet instances and invalidate the cache whenever mutable packet state changes before queueing or loopback replay.

Add compact bitmap prefilters for hash-prefix and ACK low-byte lookups so unseen keys bypass full table scans, while preserving existing exact-match checks.

This keeps memory static, avoids false negatives, and reduces repeated CPU work in duplicate suppression hot paths.
Simplify send scheduling by removing the pre-check outbound count scan and relying on a single getNextOutbound() lookup.

This eliminates repeated linear queue traversal in the hot path while preserving CAD gating, silence timing, and packet-send behavior.
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.

1 participant