Speed up SonarCloud pipeline for PR validation

Hello, we’re trying to use SonarCloud on a very large solution (over 100 projects) and integrate it into Azure Pipelines to integrate with PRs in Azure DevOps.

Without SonarCloud, the build of the solution (MSBuild /t:Build) is ~8 minutes. But when we add SonarCloud (call the “prepare” pipeline step), the build gets significantly slower to ~24 minutes. That’s because of all the additional analysis that runs as part of the compilation step.

Since we’re using this inside validation builds in PRs, only the code issues found in the changed lines are reported into the PR as comments. But still the entire solution is analyzed and slowed down, not just the changed parts.

Is there some way to make this faster? If the PR validation builds take too long, we cannot use them as it degrades the developer experience too much.

Here is a great place to start.

Hi, from the guide Colin mentioned, I would recommend to start by adding more CPUs to your build machines:

This works in practice:

Also, make sure you don’t run the analysis twice (during build and test execution).

Thank you. This will be useful if I want to get into depth on how to optimize the details.

Since SonarCloud only reports issues for the changed code, is it possible that it would only run analysis on the changed code? Is there some way of achieving that?

We are gradually working towards being able to limit the files that are analyzed in the context of PR analyses (we’ve already done this in SonarQube for languages that don’t require cross-file analysis, and implemented server-side caches for Java and C/C++ which do cross-file analysis).

These changes will eventually make their way to SonarCloud – but still leaves a few languages (mostly our flagship languages, including C#) where this still isn’t possible. Additionally, analysis of C# is done in such as specific manner (using Roslyn analyzers executed at build-time) that I’m sure there will be some additional complexity (if it’s possible at all).

So right now, the only thing you can do is focus on the optimizations described by @Andrei_Epure and that are found in the performance guide.

And, this remains a topic on our radar.

1 Like

Thank you for taking time to explain, this is exactly the information I was looking for.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.