3 ms·
LINQ methods build up a chain of IEnumerable/IQueryable objects, which then build up chains of IEnumerator objects each time you iterate. These types are all .
by debugnik 1y ago
LINQ methods build up a chain of IEnumerable/IQueryable objects, which then build up chains of IEnumerator objects each time you iterate.
These types are all .NET interfaces, which are reference types, so they're allocated on the heap. .NET's escape analysis can sometimes move reference types to the stack, but this feature is currently very limited and didn't even exist until .NET 9.
ZLinq uses generic structs to prevent these allocations at the expense of some really verbose intermediate types.
- ImHereToVote 1y agoThanks.