Skip to content

fix: Reduce cache size for slot hashes#68

Merged
adiman9 merged 1 commit intomainfrom
slot-hash
Mar 19, 2026
Merged

fix: Reduce cache size for slot hashes#68
adiman9 merged 1 commit intomainfrom
slot-hash

Conversation

@adiman9
Copy link
Contributor

@adiman9 adiman9 commented Mar 19, 2026

No description provided.

@adiman9 adiman9 merged commit ec9cba3 into main Mar 19, 2026
9 of 10 checks passed
@adiman9 adiman9 deleted the slot-hash branch March 19, 2026 17:21
@vercel
Copy link

vercel bot commented Mar 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperstack-docs Ready Ready Preview, Comment Mar 19, 2026 5:21pm

Request Review

@greptile-apps
Copy link

greptile-apps bot commented Mar 19, 2026

Greptile Summary

This PR reduces the in-memory slot hash cache retention window in SlotTracker from 10,000 slots to 1,000 slots, cutting the maximum number of entries held in the RwLock<HashMap> by 10×. This is a straightforward memory-reduction fix with no behavioural changes outside of the cache window.

  • The pruning logic in record_slot_hash now removes any slot whose number is more than 1,000 behind the current slot (slot.saturating_sub(1000) instead of slot.saturating_sub(10000)).
  • A stale inline comment on line 43 still reads "keep last 10000 slots" and should be updated to "keep last 1000 slots".
  • Trailing whitespace on the blank line after hashes.insert(...) was also cleaned up.

Confidence Score: 5/5

  • This PR is safe to merge; it is a straightforward numeric constant change with no logic or API surface modifications.
  • The change is a single-line constant reduction (10000 → 1000) inside an already-correct pruning loop. The logic is unchanged, no new edge cases are introduced, and the only follow-up needed is updating the stale comment.
  • No files require special attention beyond the stale comment on line 43 of rust/hyperstack-server/src/health.rs.

Important Files Changed

Filename Overview
rust/hyperstack-server/src/health.rs Reduces the slot hash cache retention window from 10,000 to 1,000 slots to limit memory usage; the accompanying comment was not updated to reflect the new limit.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant SlotTracker
    participant HashMap as slot_hashes (RwLock)

    Caller->>SlotTracker: record_slot_hash(slot, hash)
    SlotTracker->>HashMap: write lock acquired
    SlotTracker->>HashMap: insert(slot, hash)
    Note over SlotTracker,HashMap: Prune slots where s < slot - 1000
    SlotTracker->>HashMap: collect keys older than 1000 slots
    loop for each old slot
        SlotTracker->>HashMap: remove(old_slot)
    end
    SlotTracker-->>Caller: ()

    Caller->>SlotTracker: get_slot_hash(slot)
    SlotTracker->>HashMap: read lock acquired
    HashMap-->>SlotTracker: Option<String>
    SlotTracker-->>Caller: Option<String>
Loading

Fix All in Claude Code

Prompt To Fix All With AI
This is a comment left during a code review.
Path: rust/hyperstack-server/src/health.rs
Line: 43

Comment:
**Stale comment after cache size change**

The inline comment still references the old limit of `10000` slots, but the pruning threshold has been changed to `1000`. This makes the comment misleading and inconsistent with the code.

```suggestion
        // Prune old entries to prevent unbounded growth (keep last 1000 slots)
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "fix: Reduce cache si..."

hashes.insert(slot, slot_hash);

// Prune old entries to prevent unbounded growth (keep last 10000 slots)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Stale comment after cache size change

The inline comment still references the old limit of 10000 slots, but the pruning threshold has been changed to 1000. This makes the comment misleading and inconsistent with the code.

Suggested change
// Prune old entries to prevent unbounded growth (keep last 10000 slots)
// Prune old entries to prevent unbounded growth (keep last 1000 slots)
Prompt To Fix With AI
This is a comment left during a code review.
Path: rust/hyperstack-server/src/health.rs
Line: 43

Comment:
**Stale comment after cache size change**

The inline comment still references the old limit of `10000` slots, but the pruning threshold has been changed to `1000`. This makes the comment misleading and inconsistent with the code.

```suggestion
        // Prune old entries to prevent unbounded growth (keep last 1000 slots)
```

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code

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