VS 2022: High RAM and CPU issue with Roslyn Code Analysis
Asked Answered
L

3

65

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

Louise answered 15/6, 2022 at 7:40 Comment(2)
github.com/dotnet/roslyn/issues/19205Thirtyeight
@HansPassant Thanks, but that issue was related to VS2017Louise
S
90

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

enter image description here

after that, Visual Studio works well.

Sheldonshelduck answered 13/7, 2022 at 14:17 Comment(8)
Wow! This seems to do the trick! Thanks!!!Louise
For me it was enough to deactivate "Enable 'pull' diagnostics".Hetti
Really, I have tried it, and it working better.Orthodox
Still seems to be an issue for me, but only when building test projects and for specific solutions.Bind
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.Bind
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.Cordie
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.Kore
Disabling the "Enable 'pull' diagnostics..." made it much worse for me. With it enabled the RoslynCodeAnalysisService.exe uses 764MB. With it disabled the memory goes to 1.4GB - almost twice as bad. I am using VS Studio Community 2022 64 bit v17.8.2Leeannaleeanne
L
8

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

Liquorish answered 19/5, 2023 at 16:43 Comment(0)
A
2

This has apparently been fixed in VS2022 v17.3

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

Addend answered 16/2, 2023 at 13:7 Comment(7)
I'm using 17.5.1 and this was still an issue, although possibly the very large codebase added to the problem. Disabling "Run code analysis in separate process" did the trick for me.Blackandblue
And I am running 17.5.2, and it still beyond insane that this is occurring. So far, un-checking that pull option seems to work.Petitioner
Follow up - no, I'm still getting this high CPU issue. I have rolled back to 17.4.4, and all is fine.Petitioner
I was running 17.6 and still a problem.Joist
Still an issue in Version 17.7.4 unfortunately... that is how I got to this page.Entitle
17.9.6 still having this issue (honestly speaking I didn't notice it in previous versions).Matta
17.11.0 preview 2.1 the same problemProcumbent

© 2022 - 2024 — McMap. All rights reserved.