dotnet / roslyn-analyzers

MIT License
1.59k stars 465 forks source link

Improve performance of CA2000 (DisposeObjectsBeforeLosingScope) #4915

Open sharwell opened 3 years ago

sharwell commented 3 years ago

Analyzer

Diagnostic ID: CA2000: Dispose objects before losing scope

Analyzer source

Version: 5.0.4-preview1.21126.5

Describe the bug

CA2000 has been disabled in dotnet/roslyn-analyzers due to its pronounced impact on build times. The underlying performance issue(s) should be investigated and resolved so it can be enabled again.

Steps To Reproduce

  1. Revert d07ec24bc4dcfdbb37b390264c87c83fbb87ac77 to enable CA2000
  2. Rebuild RoslynAnalyzers.sln with /bl /p:ReportAnalyzer=true
  3. Open the Build.binlog to review the analyzer summary

Expected behavior

CA2000 should not be responsible for significant analyzer time during the build.

Actual behavior

CA2000 is responsible for the majority of all analyzer time in the build.

Additional context

CA2000 was disabled in #4862.

Youssef1313 commented 3 years ago

This analyzer had performance improvements in the past. See https://github.com/dotnet/roslyn-analyzers/issues/3738

sharwell commented 3 years ago

The observations that led to this issue were based on a commit from just a few days ago.

Youssef1313 commented 3 years ago

Yep I didn't mean this was fixed. But noting a similar issue just for reference.