Ensure the selector gets run during Count. #14435
Please consider weighing on the "side issue" if you think it is a good question.
Is there any chance of these changes to be rolled back in the future? I came across this PR while researching LINQ performance and it seems a shame that these opimisations still cannot be enabled because of bad code that relies on
Is there scope to add an additional LINQ API to force enumeration to give codebases that rely on this behaviour an easy out, while the general case can benefit?
Alternatively, is there any scope for these optimisations to be enabled if LINQ is used with static anonymous functions that are less likely to have side effects?