Very slow build time with SonarCloud

We recently incorporated SonarCloud into our Azure DevOps pipeline, build time went up by a few mins (which was expected and acceptable). However, having just upgraded the VS Build Tools version on our build servers the build time doubled from 15mins to 30+ mins.

Current setup:

  • Solution is targeting .Net Framework 4.8 - C#
  • VS Build Tools version on agent - 16.9.16
  • Quality profile - Default (Sonar way)
  • SonarScanner for MSBuild 5.4

Tried disabling a couple of (very frequently hit) rules but that made no difference. Completely disabling SonarCloud brings build time back to normal - a few mins… Not sure what else to try.

Hello and welcome to the community!

Did you read The SonarSource guide for investigating the performance of .NET analysis ?

Once you read the guide, we look forward to hearing feedback from you based on those suggestions.

Hi @Andrei_Epure

Thank you for that link, by enabling the extra logging, I’ve managed to extract analysis times per project and cannot find any single outlier.

As you can see from the extract below, there are a few projects that are quite slow, and they seem to grown in proportion of the project size.

 Total analyzer execution time: 194.734 seconds.
 Total analyzer execution time: 129.397 seconds.
 Total analyzer execution time: 86.708 seconds.
 Total analyzer execution time: 59.276 seconds.
 Total analyzer execution time: 49.765 seconds.
 Total analyzer execution time: 47.619 seconds.
 Total analyzer execution time: 44.800 seconds.
 Total analyzer execution time: 44.112 seconds.
 Total analyzer execution time: 41.242 seconds.
 Total analyzer execution time: 39.564 seconds.
 Total analyzer execution time: 38.813 seconds.
 Total analyzer execution time: 35.471 seconds.
 Total analyzer execution time: 35.253 seconds.
 Total analyzer execution time: 34.707 seconds.
 Total analyzer execution time: 30.116 seconds.
 Total analyzer execution time: 29.087 seconds.
 Total analyzer execution time: 28.566 seconds.
 Total analyzer execution time: 27.413 seconds.
 Total analyzer execution time: 27.353 seconds.
 Total analyzer execution time: 27.305 seconds.
 Total analyzer execution time: 26.942 seconds.
 Total analyzer execution time: 25.797 seconds.
 Total analyzer execution time: 25.776 seconds.
 Total analyzer execution time: 25.355 seconds.
 Total analyzer execution time: 24.842 seconds.
 Total analyzer execution time: 24.375 seconds.
 Total analyzer execution time: 23.877 seconds.
 Total analyzer execution time: 23.504 seconds.
 Total analyzer execution time: 23.078 seconds.
 Total analyzer execution time: 22.875 seconds.
 Total analyzer execution time: 22.652 seconds.
 Total analyzer execution time: 22.630 seconds.
 Total analyzer execution time: 22.153 seconds.
 Total analyzer execution time: 21.316 seconds.
 Total analyzer execution time: 21.259 seconds.
 Total analyzer execution time: 20.957 seconds.
 Total analyzer execution time: 20.319 seconds.
 Total analyzer execution time: 20.243 seconds.
 Total analyzer execution time: 19.253 seconds.
 Total analyzer execution time: 18.620 seconds.
 Total analyzer execution time: 18.600 seconds.
 Total analyzer execution time: 18.221 seconds.
 Total analyzer execution time: 18.133 seconds.
 Total analyzer execution time: 18.032 seconds.
 Total analyzer execution time: 18.007 seconds.
 Total analyzer execution time: 17.892 seconds.
 Total analyzer execution time: 17.369 seconds.
 Total analyzer execution time: 17.360 seconds.
 Total analyzer execution time: 16.922 seconds.
 Total analyzer execution time: 16.625 seconds.
 Total analyzer execution time: 16.540 seconds.
 Total analyzer execution time: 15.879 seconds.
 Total analyzer execution time: 15.861 seconds.
 Total analyzer execution time: 15.517 seconds.
 Total analyzer execution time: 14.985 seconds.
 Total analyzer execution time: 14.398 seconds.
 Total analyzer execution time: 14.094 seconds.
 Total analyzer execution time: 14.028 seconds.
 Total analyzer execution time: 13.888 seconds.
 Total analyzer execution time: 13.373 seconds.
 Total analyzer execution time: 12.853 seconds.
 Total analyzer execution time: 7.040 seconds.
 Total analyzer execution time: 0.573 seconds.
 Total analyzer execution time: 0.567 seconds.
 Total analyzer execution time: 0.544 seconds.
 Total analyzer execution time: 0.511 seconds.
 Total analyzer execution time: 0.507 seconds.
 Total analyzer execution time: 0.505 seconds.
 Total analyzer execution time: 0.480 seconds.
 Total analyzer execution time: 0.469 seconds.
 Total analyzer execution time: 0.468 seconds.
 Total analyzer execution time: 0.462 seconds.
 Total analyzer execution time: 0.460 seconds.
 Total analyzer execution time: 0.452 seconds.

Below is the truncated logs of the longest project:

2022-01-26T14:01:54.5057632Z   Total analyzer execution time: 194.734 seconds.
2022-01-26T14:01:54.5058168Z   NOTE: Elapsed time may be less than analyzer execution time because analyzers can run concurrently.
2022-01-26T14:01:54.5058599Z   
2022-01-26T14:01:54.5059085Z   Time (s)    %   Analyzer
2022-01-26T14:01:54.5059580Z    130.862   67   SonarAnalyzer.CSharp, Version=8.34.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244
2022-01-26T14:01:54.5060167Z     62.488   32      SonarAnalyzer.Rules.SymbolicExecution.SymbolicExecutionRunner
2022-01-26T14:01:54.5060821Z      8.779    4      SonarAnalyzer.Rules.CSharp.DeadStores
2022-01-26T14:01:54.5061300Z      7.440    3      SonarAnalyzer.Rules.CSharp.PrivateFieldUsedAsLocalVariable
2022-01-26T14:01:54.5061805Z      4.441    2      SonarAnalyzer.Rules.CSharp.TokenTypeAnalyzer
2022-01-26T14:01:54.5062265Z      3.037    1      SonarAnalyzer.Rules.CSharp.InfiniteRecursion
2022-01-26T14:01:54.5062739Z      2.772    1      SonarAnalyzer.Rules.CSharp.SymbolReferenceAnalyzer
2022-01-26T14:01:54.5063209Z      2.407    1      SonarAnalyzer.Rules.CSharp.VariableUnused
2022-01-26T14:01:54.5063674Z      2.230    1      SonarAnalyzer.Rules.CSharp.UnusedPrivateMember

...


2022-01-26T14:01:54.5268110Z     63.753   32   SonarAnalyzer.Security, Version=9.3.0.14923, Culture=neutral, PublicKeyToken=null
2022-01-26T14:01:54.5268619Z     63.753   32      SonarAnalyzer.Security.CSharp.UcfgGenerator
2022-01-26T14:01:54.5268966Z   
2022-01-26T14:01:54.5269395Z      0.061   <1   Microsoft.CodeAnalysis.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
2022-01-26T14:01:54.5269992Z      0.048   <1      Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerAttributeAnalyzer
2022-01-26T14:01:54.5270532Z      0.013   <1      Microsoft.CodeAnalysis.Analyzers.InternalImplementationOnlyAnalyzer
2022-01-26T14:01:54.5270911Z   
2022-01-26T14:01:54.5271352Z      0.058   <1   Microsoft.CodeAnalysis.CSharp.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
2022-01-26T14:01:54.5272068Z      0.035   <1      Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer
2022-01-26T14:01:54.5272644Z      0.007   <1      Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer
2022-01-26T14:01:54.5273202Z      0.006   <1      Microsoft.CodeAnalysis.CSharp.Analyzers.CSharpImmutableObjectMethodAnalyzer
2022-01-26T14:01:54.5273759Z      0.006   <1      Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer
2022-01-26T14:01:54.5274336Z      0.004   <1      Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerFieldsAnalyzer
2022-01-26T14:01:54.5275134Z     <0.001   <1      Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticDescriptorCreationAnalyzer

Also tried adding these environment variables at the top of the YAML but they did not make any difference to build times

# SonarCloud
- name: SONAR_SCANNER_OPTS
  value: "-Xmx8G"
- name: SONAR_DOTNET_ENABLE_CONCURRENT_EXECUTION
  value: true

In terms of hardware - our build agents are running on Azure Standard_B8ms VMs with Standard SSDs so I don’t think that’s an issue.

Do you have any other recommendations?

From what I understand, the regression happened when upgrading the VS Build Tools. Could you please tell me what was the previous version of the Build Tools?

This maybe be related to Linking System.Memory as an analyzer dependency can have a significant performance impact · Issue #58863 · dotnet/roslyn · GitHub

Would you be able to provide the logs from builds on the old Build Tools version and the new ones?

thank you.

This topic was automatically closed after 11 days. New replies are no longer allowed.