Dotnet build times really slow when running sonar-scanner

Hello, we have SonarCloud integrated in our project and we’re trying to improve the amount of time it requires to perform the analysis.

We’re running it on Github Actions as CI system and we’re using dotnet-scanner as the analysis runner for our .NetCore 3.1 project. If we build the project without dotnet-scanner the build time is around 3mins, but if we decorate that build with begin/end commands, our build time grows to 15-20mins (a 5x growth).

Is this something expected? Is there any way to debug and get more details on what is making it this slow?

Thank you so much!

Hello @adanlobato-scopely,

The architecture of the C# (and VB.NET) analyzer is quite different from all the others. The rules are actually executed during the build step, the Sonar End step is only collecting results and computing a few extra stuff. So the bulk of the analysis happens during the build and that’s why you see that increase. That is expected that the build increases. By how much ? It depends on build environment and your code. But from 3’ to 15-20’ is not crazy.

Sometimes, because of the structure of your code, some rules may take particularly long to execute.
If you want to know the execution time of each rule you can run the build in debug mode (add /d:"sonar.verbose=true"in your begin step) and this should output a rule execution time breakdown in the logs.
This may help you identify a rule that may be particularly slow on your code:

  • If one rule is really above the pack in terms of CPU time, you may report it to us (we can look at the rule logic and fine tune it for performance if we feel there’s something we can do)
  • You can (temporarily or not) disable that rule if not so important for you

Olivier