3 ms·
This is neat, but how does this get away with being zero allocation? It appears to use `Func<T,U>` for its predicates, and since `Func<T>` is a reference type
by KallDrexx 1y ago
This is neat, but how does this get away with being zero allocation? It appears to use `Func<T,U>` for its predicates, and since `Func<T>` is a reference type this will allocate. The IL definitely generates definitely seems like it's forming a reference type from what I can tell.
- ziml77 1y agoThe JIT can optimize this. I know for sure if there's no captures in the lambda it won't allocate. It's likely also smart enough to recognize when a function parameter doesn't have its lifetime extended past the caller's, which is a case where it would also be possible to not allocate.
- theolivenbaum 1y agoTo add on that, you can define your lambdas as static to make sure you're not capturing anything by mistake. Something like dates.Where(static x => x.Date > DateTime.Now)