runtime: BufferBlock slow?
Been doing some bench-marking and I thought a BufferBlock<T>
would be a great underlying collection for an Object Pool. But it just seems to be dramatically slower than a ConcurrentQueue<T>
.
Is this simply the nature of the beast? Or isn’t there a way to boost performance?
The reason why I’m not just simply using ConcurrentQueue (because it’s super fast), is that some instances of object construction and recycling can take extra time, and I’d prefer something like a Dataflow pipeline to handle it.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (7 by maintainers)
Commits related to this issue
- Commit 29810a78e5b93d8da9fb921d096226d249fc75a5 added unconditional dependency on GetCpuUtilization (#24715) Update projitems file inclusion Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com> — committed to Dotnet-GitSync-Bot/corefx by marek-safar 5 years ago
- Commit 29810a78e5b93d8da9fb921d096226d249fc75a5 added unconditional dependency on GetCpuUtilization (#24715) Update projitems file inclusion Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com> — committed to dotnet/corefx by marek-safar 5 years ago
Just chiming in… if
ConcurrentQueue
works for your needs, then go ahead and use it. You won’t get much faster than that.BlockingCollection
provides an abstraction over a concurrent collection (defaulting toConcurrentQueue
) that allows producers/consumers to wait for a notfull/notempty signal.AsyncCollection
provides (almost) the same abstraction over a concurrent collection (defaulting toConcurrentQueue
) that allows producers/consumers to asynchronously wait for a notfull/notempty signal.If you don’t need the signals, then you don’t need that abstraction, and can just use
ConcurrentQueue
directly.BufferBlock
is a much more “batteries included” type of queue. NeitherBufferBlock
norBlockingCollection
/AsyncCollection
attempt to compare performance-wise withConcurrentQueue
, but they bring their own different advantages.Yes, but as with any component A that layers functionality over B, A is going to be more expensive, e.g.
yields results like:
This isn’t a slight against AsyncCollection; anything that layered on such functionality would incur cost. I’m just highlighting why I wrote what I wrote.