44

We have a huge solution (ASP.NET MVC, C#) in Visual Studio 2022 (v.17.2.2 64bit).

Roslyn Code Analysis is always using high CPU and RAM. Is there a way to prevent this issue? A configuration or something else?

Task manager

Kit
  • 20,354
  • 4
  • 60
  • 103
kiafiore
  • 1,071
  • 2
  • 11
  • 27

3 Answers3

63

In Visual Studio 2022, I've resolved it by disabling these two checks:

enter image description here

after that, Visual Studio works well.

Pang
  • 9,564
  • 146
  • 81
  • 122
iugs88
  • 971
  • 10
  • 9
  • Wow! This seems to do the trick! Thanks!!! – kiafiore Jul 14 '22 at 12:51
  • 5
    For me it was enough to deactivate "Enable 'pull' diagnostics". – Templar_VII Dec 14 '22 at 07:23
  • Really, I have tried it, and it working better. – Ruben Dec 20 '22 at 01:21
  • Still seems to be an issue for me, but only when building test projects and for specific solutions. – BobT Dec 21 '22 at 09:19
  • 1
    EDIT: Found my particular issue; one of the unit test classes had a large (~27mb) Base64 encoded string literal as part of the unit test (as part of load testing) rather than loading in the content from an external file - obviously in this case VS was going nuts trying to analyse a ~30mb CS file. – BobT Dec 21 '22 at 09:59
  • Still super high CPU on large solutions. Disabling these didn't work from me. I had to set `Run background code analysis for:` to `None` so it's essentially disabled I assume. I'll have to toggle this back on on each update to see if this has been fixed. – ScottN May 03 '23 at 14:27
  • I have a library with a large number of classes/models in it. After including this library performance in VS was garbage. I updated to the current version, still bad. This setting seems to help as my CPUs not pegging 100% while typing now. – Gary Smith May 16 '23 at 16:18
3

It's still happening in VS2022 v17.6

I've only been able to fix it by temporarily deleting my .editorconfig file from the solution folder (and restarting VS).

This implies that the problem is some analyzer that I've turned on in .editorconfig that takes a really long time to run under some circumstances. In order to figure out which one is causing the problem I guess I'd have to turn them all off and then turn then back on one at a time to see at which point the problem came back, but I haven't had time to try that.

EDIT: I followed the instructions here to turn on analysis and logging of the build process, and then viewing the log to see which analyzers were taking the most time. I disabled those analyzers and it seems to have helped some.

EDIT: One of the analyzers that was taking a long time couldn't be turned off and it turned out to be a bug

ghosttie
  • 588
  • 2
  • 8
  • 18
2

This has apparently been fixed in VS2022 v17.3

https://developercommunity.visualstudio.com/t/vs-2022-high-cpu-use-by-servicehubroslyncodeanalys/1610702

erlando
  • 6,736
  • 4
  • 24
  • 29