Skip to content

make caching/lru a real LRU#491

Open
omar-polo wants to merge 12 commits into
mainfrom
op/lru-really-lru
Open

make caching/lru a real LRU#491
omar-polo wants to merge 12 commits into
mainfrom
op/lru-really-lru

Conversation

@omar-polo

Copy link
Copy Markdown
Contributor

context: i've added originally this package to amortize the BTree operations, but I got a bit lazy. The improvements with the FIFO were already good enough that I didn't spend the last 20% of effort for making a real LRU.

Let's revisit that.

This is a preparatory step for further BTree work that I'd like to do.

While here, augment a bit the coverage, and add a benchmark, even if I'm not sure how much useful it is and might drop it.

* add a test for more than one eviction
* test Stats() as we operate on the cache
This makes it easier to implement a real LRU, since now the behaviour
is that of a FIFO.
while here, also change the way it's managed: we push items
to the head and evict from the tail.
Get now "bumps" the retrieved element at the top of the list, which
makes eviction at the tail actually remove the last accessed item.
silently bump non-sensical values for size to a minimum of two, and
while here add some doc for the New method.
@omar-polo

Copy link
Copy Markdown
Contributor Author

open point: should i "bump" the value when Put overrides it? tempted to say yes.

@omar-polo

Copy link
Copy Markdown
Contributor Author

ah, also, (using this as a mental todo) i'd like to improve the flush method usage a bit, but only for read-ability.

in both cases, the breakage comes from the fact that the new LRU has
an implicit bigger size, so tests that were relying on tiny capacities
needed a fix.

* cache_internal_test: add a few more nodes to fill the cache
* iter_internal_test: flush the cache to restore previous behaviour
@omar-polo
omar-polo force-pushed the op/lru-really-lru branch from 43de094 to dfe7598 Compare July 12, 2026 17:08
@mathieu-plak

Copy link
Copy Markdown
Contributor

open point: should i "bump" the value when Put overrides it? tempted to say yes.

Yes, even though I don't think we have much code that uses this codepath.

@mathieu-plak mathieu-plak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, I'm a tiny bit worried about the contention on Get but that shouldn't be too too bad.

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