Antão Almada
1 min readSep 10, 2018

--

Hi Michael,

Sorry, the text is indeed misleading. This is a much simpler, easier to understand version.

The code you highlight from System.Linq can be resumed to, Enumerable.Empty() returns a reference to an Array with zero items. What you don’t see there is that, when enumerating, the Array.GetEnumerator() is called. This returns an new instance of SZArrayEnumerator, which allocates more memory because it’s a class and has three fields. Its MoveNext() implementation has to compare the current and the end positions to return false.

That implementation is all over the place and has worst performance… ;)

Thanks a lot for the feedback!

--

--

No responses yet