SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
775 stars 226 forks source link

S1128 Improve performance and add to SonarWay: UnnecessaryUsings #3761

Open andrei-epure-sonarsource opened 3 years ago

andrei-epure-sonarsource commented 3 years ago

S1128 (UnnecessaryUsings) is a code smell which doesn't bring a lot of functional value, so we don't want it to have a big performance impact on the msbuild time.

We should re-think how we use the Semantic Model inside the rule, in order to improve the performance.

From this investigation, the rule takes 38 seconds to run - 4%.

38.864 4 SonarAnalyzer.Rules.CSharp.UnnecessaryUsings

Corniel commented 3 years ago

Improving performance is a good thing! Personally I value this rule highly, as it potentially removes a lot of code, which makes code easier to read. Visual Studio also has tooling for this, I'm not sure if sonar can build on top of that (might help performance wise).

andrei-epure-sonarsource commented 3 years ago

I agree that performance is important, @Corniel. As our analyzers are used on CI systems, as well as local builds outside the IDE - we cannot rely on Visual Studio. It would be interesting to see their implementation, though.

pavel-mikula-sonarsource commented 3 years ago

This rule needs complete redesign. New idea:

mary-georgiou-sonarsource commented 2 years ago

Leaving this here as an FYI: Global using retrieval will be available from MSBuild version 17.3 onwards through this API, exposed via semanticModel.GetImportScopes.