Use local array in ConcurrentQueue<T> for small perf improvement (#21192)
authorStephen Toub <stoub@microsoft.com>
Tue, 27 Nov 2018 14:27:06 +0000 (09:27 -0500)
committerGitHub <noreply@github.com>
Tue, 27 Nov 2018 14:27:06 +0000 (09:27 -0500)
commite41401ed9c1070971d2062e971fed14d1747be78
tree9622798ae6dc62ccb8bc244dff1aac9df63f9b03
parentb01b2b8030f363368530b8a1395d604179e8d0e4
Use local array in ConcurrentQueue<T> for small perf improvement (#21192)

Enqueue/TryDequeue/TryPeek are all repeatedly accessing the same array from a readonly field.  Changing them to instead access that same array but from a cached local results in an ~10% throughput boost on a microbenchmark that does uncontended reads/writes of objects from/to the queue. (I also tried using a ref local to point directly to the target slot in the array, but that actually resulted in a measurable regression.)
src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs