Avoid taking lock for empty bucket in ConcurrentDictionary.TryRemove (#82004)
authorStephen Toub <stoub@microsoft.com>
Sun, 12 Feb 2023 23:53:55 +0000 (18:53 -0500)
committerGitHub <noreply@github.com>
Sun, 12 Feb 2023 23:53:55 +0000 (18:53 -0500)
commit252018c3d3fffdb592413cf61d5b80cf751e0a59
tree0958df939d1b2d2204a4e788e6bb69cef923f047
parent4f3308f49a03a415232c77f54ea0f3257d8f233f
Avoid taking lock for empty bucket in ConcurrentDictionary.TryRemove (#82004)

Even when uncontended, the lock represents the most expensive work performed by the method.  We can avoid taking it if we see that the bucket's count is empty.
src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs