Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 6b291a4

Browse files
committed
Rewrite ConcurrentQueue for better performance
This commit rewrites ConcurrentQueue<T> to provide better throughput and a much better allocation profile. As with the previous implementation, it's structured as a linked list of segments. Unlike the previous implementation, these segments are now ring buffers, allowing them to be reused as long as they're not full; if an enqueue does make a segment full, then a new segment is created for subsequent enqueues. Also unlike the previous implementation, segments are dynamic in size, so newly allocated segments follow a doubling scheme similar to that employed by other generic collections. The synchronization mechanism used is also lower-overhead than before, with a typical operation incurring just one CAS operation to either enqueue or dequeue.
1 parent 3e6bedf commit 6b291a4

5 files changed

Lines changed: 792 additions & 636 deletions

File tree

src/System.Collections.Concurrent/src/Resources/Strings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
<data name="ConcurrentBag_CopyTo_ArgumentNullException" xml:space="preserve">
184184
<value>The array argument is null.</value>
185185
</data>
186-
<data name="ConcurrentBag_CopyTo_ArgumentOutOfRangeException" xml:space="preserve">
186+
<data name="Collection_CopyTo_ArgumentOutOfRangeException" xml:space="preserve">
187187
<value>The index argument must be greater than or equal zero.</value>
188188
</data>
189189
<data name="ConcurrentCollection_SyncRoot_NotSupported" xml:space="preserve">

src/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public void CopyTo(T[] array, int index)
277277
}
278278
if (index < 0)
279279
{
280-
throw new ArgumentOutOfRangeException(nameof(index), SR.ConcurrentBag_CopyTo_ArgumentOutOfRangeException);
280+
throw new ArgumentOutOfRangeException(nameof(index), SR.Collection_CopyTo_ArgumentOutOfRangeException);
281281
}
282282

283283
// Short path if the bag is empty

0 commit comments

Comments
 (0)