Skip to content

feat: add LruLockMap peek/pop_lru, expand multi-threaded benchmarks - #39

Merged
SF-Zhou merged 1 commit into
mainfrom
dev
Jul 16, 2026
Merged

SF-Zhou merged 1 commit into
mainfrom
dev

Conversation

@SF-Zhou

@SF-Zhou SF-Zhou commented Jul 16, 2026

Copy link
Copy Markdown
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
Copilot AI review requested due to automatic review settings July 16, 2026 02:24

Copilot AI 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.

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::peek to read values without promoting entries in the shard LRU list.
  • Add LruLockMap::pop_lru to 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 get vs peek comparisons.

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 thread src/lru_lockmap.rs
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));
@SF-Zhou
SF-Zhou merged commit 30368ff into main Jul 16, 2026
12 checks passed
@SF-Zhou
SF-Zhou deleted the dev branch July 16, 2026 02:32
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.68421% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.89%. Comparing base (97bfc9d) to head (82ba25c).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/lru_lockmap.rs 98.68% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

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