Use local array in ConcurrentQueue<T> for small perf improvement (dotnet/coreclr...
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)
commitd0ab26a4de9687154214e6cf683b0840a9994f6a
tree8560f7bfdc28d10e848837438d623998392ecd6a
parentca3e7268f479515f646bfb5f453ba8eb880fb289
Use local array in ConcurrentQueue<T> for small perf improvement (dotnet/coreclr#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.)

Commit migrated from https://github.com/dotnet/coreclr/commit/e41401ed9c1070971d2062e971fed14d1747be78
src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs