Implement LRU cache for storing hashes to filter out for flood repeating#29
Open
Implement LRU cache for storing hashes to filter out for flood repeating#29
Conversation
a2ee202 to
74cd840
Compare
prefs is 5 char length :nerd:
Replace the fixed-size hash table with an LRU cache using actual timestamps instead of timeout-based eviction. Some busy nodes see more than 128 packets before duplicates arrive, so LRU ordering provides better eviction behavior.
74cd840 to
845c892
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the FIFO (cyclic index) hash table with an LRU cache using
uint32_t millis()timestamps. The oldest entry is evicted instead of the next sequential slot, so frequently-seen hashes stay in the table longer.Changes:
_next_idxreplaced by_last_seen[MAX_PACKET_HASHES](uint32_ttimestamps)restoreFrom(): restored hashes get fresh timestamps; empty slots stay at 0saveTo(): writes a dummy_next_idxfor backward-compatible file formatWhy this helps:
Some busy nodes see more than 128 packets before a flooded packet returns. With FIFO, a hash gets evicted after 128 new packets regardless of how recently it was seen. With LRU, actively-seen hashes stay in the table while stale ones get evicted first.
For example, the Utrecht repeater sees ~658 packets/20 min with 72 neighbors. With FIFO:
With LRU, recently-seen hashes survive even under high packet volume, so only truly stale entries get evicted.
Memory cost: +384 bytes (
uint32_t[128]replacesint _next_idx)Build firmware: Build from this branch
Mirror of meshcore-dev#1380