Re:.NET 6 vs .NET 5 speedup
by foepys on Monday November 22, 2021 @12:46AM
(#29303206)
LINQ is parsing a tree of System.Linq.Expression here and the cases of First(pred) etc. are just not optimized because of the added complexity with little benefit. It only recently became a problem when Visual Studio got a new built-in analyzer that tells people to "optimize" this.
[ Parent
| on HN ]
If you're using LINQ on a list, it will not use Expressions, but a plain Func. So nothing will get parsed either way.
The difference, as @sbelskie already mentioned, is that Where has an optimization for List, while First only uses the naive enumerator.