Streaming and Non-Streaming in Deferred Execution (LinQ) C#
Before we start we recap some topic
Immediate execution
Immediate execution (IE) means that the LINQ method executes in the same line as you see it. A method that uses IE evaluates the LINQ query and produces a concrete result by accessing a data source or a memory location; this is a program flow that we all know.
Like: First, ToList, All, Average, Any
Deferred execution
Deferred execution means that no work happens (no data source is accessed) until we force the LINQ query to be evaluated.
Like: where,Skip,Take,Select,OrderBy
The benefits of deferred execution enable combining different operations to build the final query, before evaluating the values
Deferred-Streaming Execution
Streaming operators can yield results as soon as they find one. They don’t have to read the whole data source before returning any results and this is the key difference between streaming and non-streaming.
You can read about yield
let’s do a simple example to show how streaming done
Output
we note that it processes the three operations Where and Select, Take for 4, and the same steps it has done for 5 and does not take 6 this is the power of streaming data is through a pipeline
Where and Skip, Take these keywords to work streaming
Deferred — Non-streaming
Non-streaming operators, unlike their streaming, need to read the whole data source before they start returning even a single result.
The same above example but add OrderBy, The output
we note to her that 6 is processed by where because OrderBy does not work streaming and waits for all data before processing it, because order can’t work in one element it needs a collection of data so can sort it.
OderBy and GroupBy, Join these keywords not work streaming
Summary