The debug session shown is from the sample program provided on How to: Implement a Producer-Consumer Dataflow Pattern.
In System.Threading.Tasks.Dataflow, why are the standard block types such as BufferBlock implemented with a List rather than a Queue? Most of the dataflow blocks (especially BufferBlock<T>
) are intended to be used as FIFO, but popping the head of a list is O(n)
rather than O(1)
for Queue. Mainly I'm curious if anyone has any insight into a possible rationale for this design.
Never make any conclusions based on debugging session, examine the source first.
Consider the class information for BufferBlock<T>
public IEnumerable<T> Queue { get { return _sourceDebuggingInformation.OutputQueue; } }
As you can see, the Queue
property here coming from a debugging information field.
Let's take a look for that class:
internal IEnumerable<TOutput> OutputQueue { get { return _source._messages.ToList(); } }
Again, as you can see, this is not list-based queue, it's the queue being transformed to list for debugging.
Finally, let's see what type has the _messages
field. It's SingleProducerSingleConsumerQueue<T>
, which works exactly how it should.