Repository navigation
Conversation
Signed-off-by: Zixin Wang <[email protected]>
wzxzhuxi
marked this pull request as ready for review
November 30, 2026 07:39
This branch has not been deployed
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.
Summary
Change
Semaphore::try_acquire_owned,Mutex::try_lock_owned, andRwLock::{try_read_owned, try_write_owned}to takeself: &Arc<Self>and clone theArconly after a successful acquisition. Failed attempts no longer increment and decrement the reference count, which shares a cache line with the lock's state and caused cross-core contention under load shedding.RwLockacquires the borrowed access token first and transfers permit ownership to theArconly on success, keeping the failure path a plain atomic load.pool::unbounded::Pool::try_get.Arc;CHANGELOG.mdrecords the change under## Unreleasedas a breaking change.Benchmark
Failure paths on a saturated semaphore or held lock, comparing
v0.8.1against this branch with the same microbenchmark (--releasewith thin LTO, pinned CPUs 0-7, minimum of 3 runs; AMD Ryzen 5 5600H, x86_64 Linux):Semaphore::try_acquire_ownedMutex::try_lock_ownedRwLock::try_read_ownedRwLock::try_write_ownedSuccessful acquisition is unchanged in this microbenchmark (1-thread minimum: 10.0 ns on
v0.8.1vs 10.1 ns on this branch). Calling the new methods with the oldarc.clone().try_*_owned()style reproduces thev0.8.1numbers, confirming the difference comes from the removed reference-count operations rather than measurement noise.Verification
cargo x buildandcargo x test(workspace unit tests, integration tests, and doctests)cargo +nightly x check(feature matrix with-Dwarnings)cargo +nightly x lint(clippy, rustfmt, taplo, typos, hawkeye, and docsrs rustdoc)cargo +nightly x miriwith the CIMIRIFLAGS(-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-many-seeds=0..4)Fixes #468