Skip to content

statement-store: Unbounded expired HashMap causes ~9GB+ memory bloat during high throughput #11665

@DenzelPenzel

Description

@DenzelPenzel

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Request

The statement store maintains an in-memory expired:

expired: HashMap<Hash, u64>, // Value is expiration timestamp.
that tracks hashes of removed/evicted statements to prevent peers from re-gossiping them.

  1. Unbounded growth, unlike entries (capped at 4M statements / 2GiB), the expired map has no capacity limit
  2. Inefficient purge
    self.expired.retain(|hash, timestamp| {

During high-throughput scenarios the expired map grows to ~100M entries, consuming an estimated ~9GB of RAM (100M entries × 104 bytes: 32-byte hash + 8-byte timestamp + ~64 bytes HashMap overhead)

Solution

Replace the flat HashMap<Hash, u64> with a time-bucketed ExpiredIndex:

struct ExpiredIndex {
      /// O(1) dedup lookup (hash -> bucket_id)
      lookup: HashMap<Hash, u64>,                                                                                                      
      /// Time buckets ordered by age (bucket_id -> set of hashes)
      buckets: BTreeMap<u64, HashSet<Hash>>,                                                                                           
  }                  

Are you willing to help with this request?

Yes!

Metadata

Metadata

Assignees

Labels

I5-enhancementAn additional feature request.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions