Open marco-carvalho opened 1 month ago
Like https://github.com/SonarSource/sonar-dotnet/issues/9664#issuecomment-2357877600 , List.Exists
remained unchanged while Any
was optimized.
Hello @marco-carvalho,
Thank you for pointing this out. As for #9664, we will take a look when we prepare for the .NET 9 release!
Have a great day!
I think advising the other way around does not make sense. We're dealing with a difference of 2 nanoseconds. You could consider report to Microsoft thought, as it is strange that a native method (.Exists
) turns out to be slower than an extension method.
Hello,
The rule S6605 may no longer be applicable for projects targeting .NET 9.0.
Recent benchmarks indicate that starting with .NET 9.0,
Any
is actually faster thanExists
. Below are the benchmark results.Code:
Results:
Maybe this rule for code targeting .NET 8.0 or below, and a new rule
"Any" method should be used instead of the "Exists"
for code targeting .NET 9.0 or above?