Skip to content

IdempotencyStore.prune runs on every claim, scanning the whole map under load #55

@nficano

Description

@nficano

In arcp-runtime/src/main/java/dev/arcp/runtime/idempotency/IdempotencyStore.java the claim method around line 43 calls prune() on line 45 as its first action. prune() in turn iterates entries.values() and calls removeIf with a clock-based check on every entry. With the default TTL of 24 hours the entry set can hold tens of thousands of records under sustained load, and every new submit pays the O(n) walk. The pruning logic itself is correct; the call frequency is wrong. Most production deployments prune expired entries on a scheduled cadence (every minute, every 5 minutes) rather than synchronously per write.\n\nFix prompt: In arcp-runtime/src/main/java/dev/arcp/runtime/idempotency/IdempotencyStore.java replace the in-line prune call with a scheduled task. Add a constructor parameter ScheduledExecutorService scheduler (or accept a Clock-driven "prune now" hook), and schedule prune() to run every minute (or at a frequency configurable via Builder; one minute is a reasonable default for a 24-hour TTL). The store should expose a public prune() method for tests to call deterministically. Wire the scheduling from arcp-runtime/src/main/java/dev/arcp/runtime/ArcpRuntime.java where IdempotencyStore is constructed around line 85 — pass the runtime's existing scheduler. Add a unit test that pre-populates 10 000 entries, advances a test Clock past the TTL, calls prune explicitly, and asserts the entry set is empty without ever paying the cost in claim(). Confirm existing IdempotencyStore tests still pass with no scheduling involved (call prune directly in test setup if needed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance and resource-efficiency workseverity:lowLow severity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions