Hi,
I saw Nick's video about using List<>.Find vs Linq.FirstOrDefault, and I think that it can be good to reconsider this rule.
TLDW:
List<>.Find is faster than Linq.FirstOrDefault but only in <=net8.0, with net9.0 FirstOrDefault is optimized to use spans, and it beats List<>.Find.
It may seem reasonable to report it for <=net8.0, but it will create more work in the future. My thought is to remove this recommendation (for all versions) and reverse it (since net9)
Version of the Meziantou.Analyzer NuGet package
2.0.163
Rule Identifier
MA0020
Target Framework
net9.0
C# Language version
13
Description
Hi, I saw Nick's video about using
List<>.Find
vsLinq.FirstOrDefault
, and I think that it can be good to reconsider this rule.TLDW:
List<>.Find
is faster thanLinq.FirstOrDefault
but only in <=net8.0, with net9.0FirstOrDefault
is optimized to use spans, and it beatsList<>.Find
.It may seem reasonable to report it for <=net8.0, but it will create more work in the future. My thought is to remove this recommendation (for all versions) and reverse it (since net9)
Reproduction Steps
https://www.youtube.com/watch?v=UfjRoshu23w&t=623s
Other information
No response