Skip to content

feat: add LruLockMap batch_lock; dedup State and release protocol into common module - #41

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

feat: add LruLockMap batch_lock; dedup State and release protocol into common module#41
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 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)
Copilot AI review requested due to automatic review settings July 16, 2026 03:37

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 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_lock that locks keys in a consistent sorted order via BTreeSet.
  • Deduplicate per-entry State (now generic over an extra payload) and the reference-release CAS fast path into src/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 thread src/lru_lockmap.rs
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);
@SF-Zhou
SF-Zhou merged commit a022f47 into main Jul 16, 2026
11 of 14 checks passed
@SF-Zhou
SF-Zhou deleted the dev branch July 16, 2026 03:46
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.29%. Comparing base (b659cd5) to head (69a9375).
⚠️ Report is 3 commits behind head on main.

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.
📢 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