Conversation
SF-Zhou
commented
Jul 16, 2026
Owner
- Add batch_lock to LruLockMap: deadlock-safe multi-key locking via sorted BTreeSet order; held keys are never evicted (refcnt > 0 is skipped by try_evict), plus an 8-thread concurrent test
- Generalize the per-key State as State<K, V, L> in src/common.rs, where L is an extra link payload: () for LockMap and the intrusive LRU list pointers (Links) for LruLockMap; layout is unchanged (links: () is a ZST, field nesting is compile-time)
- Extract the reference-release CAS fast path into State::release_ref_needs_cleanup(), removing the duplicated protocol from both maps' release_ref
- Verified: 69 unit tests + 44 doctests, clippy -D warnings, full Miri and ThreadSanitizer runs all clean; criterion comparison vs pre-refactor baseline shows no significant regression on any benchmark (several hot paths slightly improved from codegen side effects)
…o common module - Add batch_lock to LruLockMap: deadlock-safe multi-key locking via sorted BTreeSet order; held keys are never evicted (refcnt > 0 is skipped by try_evict), plus an 8-thread concurrent test - Generalize the per-key State as State<K, V, L> in src/common.rs, where L is an extra link payload: () for LockMap and the intrusive LRU list pointers (Links) for LruLockMap; layout is unchanged (links: () is a ZST, field nesting is compile-time) - Extract the reference-release CAS fast path into State::release_ref_needs_cleanup(), removing the duplicated protocol from both maps' release_ref - Verified: 69 unit tests + 44 doctests, clippy -D warnings, full Miri and ThreadSanitizer runs all clean; criterion comparison vs pre-refactor baseline shows no significant regression on any benchmark (several hot paths slightly improved from codegen side effects)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends LruLockMap with deadlock-safe multi-key locking (batch_lock) and refactors shared per-entry bookkeeping into src/common.rs so LockMap and LruLockMap reuse the same State and reference-release fast path.
Changes:
- Add
LruLockMap::batch_lockthat locks keys in a consistent sorted order viaBTreeSet. - Deduplicate per-entry
State(now generic over an extra payload) and the reference-release CAS fast path intosrc/common.rs. - Update docs/changelog to reflect the new API and internal refactor.
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 | Introduces batch_lock, moves LRU link pointers into a payload type, and switches to shared State + shared release fast path; adds a concurrency test. |
| src/lockmap.rs | Switches to the shared State type and shared release_ref_needs_cleanup() fast path. |
| src/common.rs | Adds the shared State<K,V,L> implementation and extracts the reference-release CAS fast path into release_ref_needs_cleanup(). |
| README.md | Documents batch locking support for LruLockMap. |
| CHANGELOG.md | Notes the new batch_lock API and internal deduplication work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+946
to
+949
| /// let mut locked = cache.batch_lock::<std::collections::HashMap<_, _>>(keys); | ||
| /// locked.get_mut(&1).and_then(|entry| entry.insert(101)); | ||
| /// locked.get_mut(&2).and_then(|entry| entry.insert(201)); | ||
| /// drop(locked); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #41 +/- ##
==========================================
- Coverage 99.29% 99.29% -0.01%
==========================================
Files 3 3
Lines 2277 2272 -5
==========================================
- Hits 2261 2256 -5
Misses 16 16 ☔ 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.