Repository navigation
Replies: 2 comments 1 reply
|
This code ports the internal implementation. SpinLock is used simply for its size (absl::Mutex is 8 bytes, while SpinLock is half that at 4 bytes). Each bucket allocates one SpinLock. Since a bucket has only 9 entries, (i.e,, size/9 SpinLock is allocated), using Mutex would overhead much memory. |
1 reply
|
It appears Abseil's spinlock is optimized for the common scenario where no one else is currently acquiring the lock, so further investigation into its performance may be necessary. Additionally, the allocation size has been slightly improved by removing std::optional. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Spun off from #1493 (comment)
While reading
base/container/flat_concurrent_cache.h, I noticed that the per-bucketabsl::base_internal::SpinLockends up protecting any user-defined copy / move / destructor ofKeyandValue:mozc/src/base/container/flat_concurrent_cache.h
Lines 71 to 80 in 9df9774
mozc/src/base/container/flat_concurrent_cache.h
Lines 82 to 101 in 9df9774
For
FlatConcurrentCache<std::string, std::string>with strings beyond the SSO threshold, each of those can callnew/delete— heap work, and a potential page fault, under a spinlock.Note that this is not a "100% CPU burning" failure mode:
absl::base_internal::SpinLock's slow path falls through toSpinLockDelay, which on Windows isSleep(0)thenSleep(N ms). Contenders do sleep. But that also means under contention every waiter pays a syscall + thread-yield, which is approximately the latency profile ofabsl::Mutexanyway — minus the wait queue and contention profile thatMutexactually gives us.We are already violating Abseil's Compatibility Guideline here:
If there is no effective difference in the latency profile, can we just use
absl::Mutexhere?All reactions