This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delay Random allocation in ConcurrentStack
ConcurrentStack currently uses a randomized-backoff scheme, where under contention it spins for increasingly longer periods of time, with a duration influenced by some randomness. If the initial attempt at popping an item fails due to contention, it allocates a Random, then tries again one or more times, and then uses the randomness to influence backoff for subsequent attempts. While it's not clear to me that this scheme is optimal, we can at least delay the allocation of the Random (and the underlying cost it entails, like an int[] in its ctor) until it's actually used. Since it's typically not used for a few attempts, this significantly decreases the number of instances that get created under heavy contention.
- Loading branch information