Skip to content

[PeerX Backlog # 65] Use bit shifts for power-of-two rate-limit windows #65

Description

@ameeribro4-sudo

Problem Statement
TimeWindow::hourly(timestamp) = (timestamp / 3600) * 3600.

While the existing fast_window does support power-of-two bitwise
optimization, the cache layer (hourly_cached) always stores one
entry per session — not per user, not per power-of-two window.

Expected Outcome
Per-user CachedWindow storage so cooldown_ms reads are O(1).

Acceptance Criteria

  • cleanup_rate_limits reduced to constant-time.
  • Test: 1000 user rate-limit reads in < 1 µs each.

Files Affected

  • peerx-contracts/counter/src/rate_limit.rs.

Difficulty / Effort 🥑 / M
Labels performance

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26performancePeerX Backlog label performance (bulk-imported)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions