Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Alex-Sob
Copy link

@Alex-Sob Alex-Sob commented Aug 17, 2025

I have a few suggested performance improvements in DataFlowAnalysis:

  1. .Any() call on PooledSortedSet<T> is Enumerable.Any extension method call, that type does not have its own Any method like some types do, e.g. ArrayBuilder<T>. As Enumerable.Any performs type checks, it should be better to check .Count.

    I believe there's a standard CA1860 rule for those kind of cases. As it's included in Minimum analysis mode, I also prepared PR Use AnalysisMode=minimum in Microsoft.CodeAnalysis.NetAnalyzers and fix errors (perf rules) #50367 to start catching these errors.

  2. There are a few issues with the part of code in RunCore method:

    • It calls .Where allocating an enumerable
    • Delegate passed to .Where creates closure
    • Enumerable returned by .Where is enumerated multiple times.

    I'd suggest to re-write that part with a simple loop to avoid these issues.
    Regarding multiple enumeration, there's a standard CA1851 rule, I believe it was added in .NET 7.

  3. The delegate passed to .Any call in HasUnprocessedPredecessorBlock also creates closure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants