Skip to content

[IDX-7032] Move to ticket-based eviction system when cache is full#40

Open
dalloriam wants to merge 5 commits into
nextfrom
feature/IDX-7025-performance-improvements
Open

[IDX-7032] Move to ticket-based eviction system when cache is full#40
dalloriam wants to merge 5 commits into
nextfrom
feature/IDX-7025-performance-improvements

Conversation

@dalloriam

@dalloriam dalloriam commented May 14, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Changes the evict-on-insert from pessimistic to optimistic, using a ticket-based eviction mechanism (src)
    • Previous system expected the insert + evicts to fail, copied the eviction policy to non-destructively determine the set of keys to evict, and then performed the eviction
    • New system expects the insert + evicts to succeed, but keeps enough data to rollback if the insert fails (i.e. if a key to be evicted is preferred in cache over the key being inserted).
    • Even in worst-case scenarios, the new system performs less allocations and is overall faster than the old one.
  • Fixes a bug where on_cache_hit was called twice on the eviction policy (src)
  • Fixed iterator implementations + misc. refactor in GDSF (src)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors cache eviction/constraint handling to a ticket-based flow: eviction policies now pop_victim() to produce a rollbackable ticket, and constraint policies return tickets (prepare_insert / prepare_replace) that become satisfied as evictions are registered. This lets the cache collect evictions without copying the whole constraint policy and supports aborting an insert by rolling back policy state.

Changes:

  • Replace eviction-policy victim iteration APIs with pop_victim() + rollback(ticket) (LRU / SLRU / GDSF) and update tests accordingly.
  • Introduce constraint “prepare” tickets for count/memory constraints and update cache insert/replace eviction collection logic to use them.
  • Fix cache-hit event dispatch so hits are delivered once per policy, and add a regression test.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/src/policy/eviction_segmented_lru_tests.cpp Updates SLRU tests to use pop_victim() + rollback-based victim enumeration.
tests/src/policy/eviction_lru_tests.cpp Updates LRU tests to use ticket-based victim popping/rollback.
tests/src/policy/eviction_gdsf_tests.cpp Updates GDSF tests to use pop_victim() + rollback and validates victim ordering.
tests/src/policy/constraint_memory_tests.cpp Updates memory-constraint tests to use prepare_insert/prepare_replace tickets.
tests/src/policy/constraint_count_tests.cpp Updates count-constraint tests to use prepare_insert/prepare_replace tickets.
tests/src/memory_cache_tests.cpp Adds regression test for replacement flow where the original key can be evicted mid-operation.
tests/src/event_dispatch_tests.cpp Adds regression test ensuring cache-hit events are delivered once per policy.
tests/CMakeLists.txt Adds the new event dispatch test file to the test target.
include/cachemere/policy/eviction_segmented_lru.h Replaces victim iterators with eviction tickets and rollback.
include/cachemere/policy/eviction_lru.h Replaces victim iterators with eviction tickets and rollback.
include/cachemere/policy/eviction_gdsf.h Replaces victim iterators with eviction tickets and rollback for GDSF.
include/cachemere/policy/constraint_memory.h Replaces can_add/can_replace with prepare tickets that accumulate freed memory via registered evictions.
include/cachemere/policy/constraint_count.h Adds prepare tickets (but leaves can_add declared).
include/cachemere/cache.h Implements ticket-based eviction collection, adds remove_popped_victim, and fixes cache-hit dispatch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/cachemere/cache.h
Comment thread include/cachemere/policy/eviction_gdsf.h
Comment thread include/cachemere/policy/constraint_count.h Outdated
Comment thread tests/src/event_dispatch_tests.cpp
Comment thread tests/src/policy/eviction_lru_tests.cpp
Comment thread tests/src/policy/eviction_segmented_lru_tests.cpp Outdated
@dalloriam
dalloriam marked this pull request as ready for review May 21, 2026 15:27
@dalloriam dalloriam changed the title Move to ticket-based eviction system when cache is full [IDX-7032] Move to ticket-based eviction system when cache is full May 21, 2026
Base automatically changed from feature/IDX-7025-modernize to next May 25, 2026 13:41
@dalloriam
dalloriam force-pushed the feature/IDX-7025-performance-improvements branch from 91649b0 to f0d0931 Compare May 26, 2026 17:28
@dalloriam
dalloriam requested a review from bourque-julien May 28, 2026 15:11
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.

2 participants