Version Used:
Visual Studio 2017
Steps to Reproduce:
Expected Behavior:
Visual Studio does not compile/analyze my solution until I explicitly request compilation.
Actual Behavior:
Visual Studio appears to be compiling/analyzing my solution which consumes CPU cycles as I continue to write code.
I have the exact same issue:
Please don't take my questions as an attempt to discredit your issue, as I definitely do value work to improve the situation taken at face value. :smile:
I'm curious if you have any suggestions for specific scenarios we should be optimizing for that would help you in particular. For example:
Is there any other specific benefit you're hoping to bring about by reducing the CPU usage here, that could help with the long-term story surrounding why improvements in this area are important to customers? This could be general things, or even things specific to you and the way you work.
Thank you for your response.
I must profess that the line between what is provided by Visual Studio and what is provided ReSharper is sometimes somewhat blurry to me, but to the best of my knowledge, all of the code refactorings and code analysis I leverage is provided by ReSharper.
Additionally, it appears as though solutions which are open in the background but share a common project will undergo the same analysis when a code a file in a common project is saved. My preferred workflow is to have multiple solutions open but I have chosen not to do this anymore due to excessive CPU usage.
Tagging @heejaechang, @mavasani, and @panopticoncentral, @CyrusNajmabadi
Can you also answer:
If you do have any/all of those enabled, can you try disabling them to see if one of them is a particular offender? Those are the 3 things that I know that we run in that process so far...
Ah.
Thank you for your help.
I had the same problem until I disabled Code Lens. Very high CPU usage and not so big solution file.
I think this issue should be kept open as the problem still persists, even though there are workarounds.
I'd still like to use Code Lens.
@Z1ni If you open your own issue, then you'll be able to decide when it's resolved (or not). This issue was closed by the author because one specific situation was resolved to their satisfaction, and my hope would be to do the same for you. 馃憤
@sharwell If I would open my own issue, it would be a duplicate of this.
I don't see why there should be a duplicate when this issue has workarounds listed, labels set and devs tagged.
@Z1ni The first thing I'd like to try is narrowing down which CodeLens feature(s) are most responsible for the situation you've observed. Can you start by disabling everything except Show References (which can't be disabled) and see if the situation improves? If you notice a big improvement, then it means one of the optional features was contributing to what you observed. In that case, you could work through the four categories in this image and try to gauge the performance relative to the case where only Show References is enabled.
I'm not quite sure why this issue is closed as it is still quite prominent.
It should be noted that the project I'm working on is fairly large, and uses StyleCop.Analyzers on all projects.
However I find that just placing a single space in a file kicks off this big spike in CPU usage. It peaks at around 80%.
I know nothing of the internals of the code analyser, but I find it weird that a single space in a file would require analysis of the entire project.
Using VS2017 update 2.
@mvestergaard since we don't restrict what analyzer can do, also since engine doesn't know what each analyzer wants to produce, we can't arbitrarily skip running analyzers on changes. whatever change it is, if user changed source, we had to run analyzers.
some of our internal analyzers we know specifically what it does, so for those, we can optimize to skip analysis on such change (space changes), but there are style analyzer which even care about space changes, so we had to run analyzers.
if High CPU is something that bothers you, you can turn full solution analysis off (Tools->Options->TextEditor->C#->Advanced).
@heejaechang Full solution analysis is off already.
@mvestergaard then the CPU is not due to analyzer then. probably due to code lens. can you turn off code lens?
if you have any solution wide features on that runs automatically on source changes, it will use high CPU if solution is big.
@heejaechang Odd, I'm not seeing anywhere near the CPU usage I saw earlier today right now. So it might have fixed itself with a restart of VS.
I'll try disabling codelens if the issue appears again. Thanks for the replies.
Yes! Disable CodeLens and my CPU usage drops, Visual Studio responds to key presses in a timely fashion, intellisense is speedy once again, and my laptop battery survives for extra hours!
It's a shame: I really like CodeLens.
Perhaps there should be an option to automatically disable when running on battery power?
I had the exactly same result. Waiting Visual Studio team to address this issue.
@creationw the process run as low priority to do solution wide features. so it is expected to use high CPU if machine is Idle.
if you don't like high CPU usages, you should turn off those solution wide features that are expensive to run such as code lens, live unit testing, source based test discovery, full solution analysis.
if you believe the process still uses a lot of CPU time even after you turned off all ambient solution wide features (features that just run if you machine is idle), can you send us traces using VS feedbacks so that we can take a look what is taking the CPU?
Hi, I have been experiencing the same problem in VS2017 recently, but in my case the performance degrades so much that typing and mouse clicks are affected - they end up being completely misjudged by the IDE. The problem gets worse over time until my mouse freezes for minutes at a time and then forever, requiring a hard reset of my machine. I have a perfview capture of one of the mouse freezing spikes and it's almost entirely inside ServiceHub.RoslynCodeAnalysisService32.exe.
I am going to try some of the suggestions here to narrow down the features and report back.
@rocifier Your best bet is to follow the steps in https://aka.ms/reportPerf and reference @sharwell in the description of the issue.
Thanks, I just submitted it now. My zipped .etl was hundreds of megs but it sent almost instantaneously.
@sharwell Want to do me a favor and check the full trace sent through? I forgot to mention you in the report description XD. EDIT: The report popped up here: https://developercommunity.visualstudio.com/content/problem/482398/servicehubroslyncodeanalysisservice32exe-high-cpu.html
@sadeghitk can you file a new issue for that?
Will do.
Most helpful comment
I'm not quite sure why this issue is closed as it is still quite prominent.
It should be noted that the project I'm working on is fairly large, and uses StyleCop.Analyzers on all projects.
However I find that just placing a single space in a file kicks off this big spike in CPU usage. It peaks at around 80%.

I know nothing of the internals of the code analyser, but I find it weird that a single space in a file would require analysis of the entire project.
Using VS2017 update 2.