Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S1854 Performance: Rule can be very slow in some scenarios #5384

Closed
costin-zaharia-sonarsource opened this issue Feb 11, 2022 · 4 comments · Fixed by #5403
Closed

Fix S1854 Performance: Rule can be very slow in some scenarios #5384

costin-zaharia-sonarsource opened this issue Feb 11, 2022 · 4 comments · Fixed by #5403
Assignees
Labels
Area: CFG/SE CFG and SE related issues. Type: Performance It takes too long.
Milestone

Comments

@costin-zaharia-sonarsource
Copy link
Member

costin-zaharia-sonarsource commented Feb 11, 2022

Description

Source: https://community.sonarsource.com/t/azure-devops-build-stuck-after-migrating-from-sq-9-1-to-sq-9-2/56783

When analyzing the reproducer project created by our user, the rule https://rules.sonarsource.com/csharp/RSPEC-1854 increased the build time from ~1m to ~130m.

I can reproduce the issue on my side and it was confirmed by the user that deactivating the rule will fix the problem.

At the first glance the problem is in the new CFG generation code since IOperationWrapperSonar has 48.4% of the memory allocations (considering only our code):
image

and uses a significant part of the processor time:
image

Repro steps

Analyze the repro project created by the user.

Expected behavior

The analysis finishes in a reasonable time.

Actual behavior

The total build time increases from 1m without the rule, to 130m when the rule is active.

Known workarounds

Removing the rule from the quality profile.

Related information

@costin-zaharia-sonarsource costin-zaharia-sonarsource added Area: CFG/SE CFG and SE related issues. Type: Performance It takes too long. Type: Bug Exceptions and blocking issues during analysis. labels Feb 11, 2022
@costin-zaharia-sonarsource costin-zaharia-sonarsource changed the title S1854 can be very slow in some scenarious S1854 can be very slow in some scenarios Feb 11, 2022
@pavel-mikula-sonarsource
Copy link
Contributor

Also reported in #5382 by @rauhs:

PackageReference Include="SonarAnalyzer.CSharp" Version="8.33.0.40503"
Analyzer Summary
    14:22.455   SonarAnalyzer.CSharp, Version=8.33.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244
        SonarAnalyzer.Rules.CSharp.DeadStores (S1854) = 6:25.949
        SonarAnalyzer.Rules.CSharp.PrivateFieldUsedAsLocalVariable (S1450) = 1:22.248
        SonarAnalyzer.Rules.CSharp.ClassAndMethodName (S100, S101) = 23.728 s
        [...]
    2:32.987   Microsoft.CodeAnalysis.NetAnalyzers, Version=6.0.5.1901, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        Microsoft.CodeQuality.Analyzers.Maintainability.AvoidDeadConditionalCode (CA1508) = 47.422 s
        Microsoft.NetCore.Analyzers.Security.ReviewCodeForInformationDisclosureVulnerabilities (CA3004) = 20.500 s
        Microsoft.NetCore.Analyzers.Runtime.DisposeObjectsBeforeLosingScope (CA2000) = 16.725 s
        [...]

I've reported it also to Roslyn: dotnet/roslyn-analyzers#5870

@pavel-mikula-sonarsource pavel-mikula-sonarsource removed the Type: Bug Exceptions and blocking issues during analysis. label Feb 15, 2022
@pavel-mikula-sonarsource
Copy link
Contributor

@rauhs Can you share a reproducer with us? By public or private channel.

@pavel-mikula-sonarsource
Copy link
Contributor

Side effect: Memory allocation issue is fixed in #5401

@pavel-mikula-sonarsource
Copy link
Contributor

This doesn't reproduce on my machine. I can rebuild it with all rules in 10 minutes. There are things to improve, but they are not the root cause of this.

@pavel-mikula-sonarsource pavel-mikula-sonarsource removed their assignment Feb 16, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 8.36 milestone Feb 17, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title S1854 can be very slow in some scenarios Fix S1854 Performance: Rule can be very slow in some scenarios Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CFG/SE CFG and SE related issues. Type: Performance It takes too long.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants