Conversation
SF-Zhou
commented
Jul 16, 2026
Owner
- Add peek(): read a value without promoting it in the LRU list (~3x faster than get() in a 4-thread read benchmark, since no move_to_front write happens under the shard lock)
- Add pop_lru(): remove and return a least-recently-used entry; per-shard LRU order with round-robin shard selection, in-use entries are skipped like the eviction policy
- Extract key/value ownership on pop via AliasableBox::into_unique
- Add 8 tests covering peek promotion semantics, pop_lru ordering, in-use/empty entry skipping, multi-shard draining and concurrency
- Rewrite benches: concurrent get, mixed get/insert, hot-key entry contention, LRU get vs peek, and mixed workload under eviction pressure, each at 1/4/8 threads with throughput reporting
- Add peek(): read a value without promoting it in the LRU list (~3x faster than get() in a 4-thread read benchmark, since no move_to_front write happens under the shard lock) - Add pop_lru(): remove and return a least-recently-used entry; per-shard LRU order with round-robin shard selection, in-use entries are skipped like the eviction policy - Extract key/value ownership on pop via AliasableBox::into_unique - Add 8 tests covering peek promotion semantics, pop_lru ordering, in-use/empty entry skipping, multi-shard draining and concurrency - Rewrite benches: concurrent get, mixed get/insert, hot-key entry contention, LRU get vs peek, and mixed workload under eviction pressure, each at 1/4/8 threads with throughput reporting
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends LruLockMap with two new LRU-oriented operations—peek (read without LRU promotion) and pop_lru (explicitly remove an LRU entry)—and updates tests, docs, and benchmarks to cover and measure the new behavior.
Changes:
- Add
LruLockMap::peekto read values without promoting entries in the shard LRU list. - Add
LruLockMap::pop_lruto remove and return a per-shard LRU entry with round-robin shard selection. - Expand tests/documentation and rewrite Criterion benchmarks to include multi-threaded workloads and
getvspeekcomparisons.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/lru_lockmap.rs | Implements peek/pop_lru and adds test coverage for semantics and concurrency. |
| src/lib.rs | Documents the new LRU inspection/removal APIs in crate-level docs. |
| README.md | Updates the public README with peek/pop_lru feature notes and examples. |
| CHANGELOG.md | Records the new APIs and benchmark expansion in the changelog. |
| benches/bench_lockmap.rs | Reworks benches to include multi-threaded workloads and LRU get vs peek. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2095
to
+2103
| let entry = cache.entry(1); | ||
| let peeker = { | ||
| let cache = cache.clone(); | ||
| // peek on a held key blocks until the guard is released. | ||
| std::thread::spawn(move || cache.peek(&1)) | ||
| }; | ||
| std::thread::sleep(std::time::Duration::from_millis(10)); | ||
| drop(entry); | ||
| assert_eq!(peeker.join().unwrap(), Some(10)); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #39 +/- ##
===========================================
- Coverage 100.00% 99.89% -0.11%
===========================================
Files 3 3
Lines 1812 1964 +152
===========================================
+ Hits 1812 1962 +150
- Misses 0 2 +2 ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.