vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

CPP.IntelliSense and CPP.Extension constant cpu load 50% on huge project

Open jphw opened this issue 6 years ago • 15 comments

Env MacBook Pro (15-inch, 2018) OS and Version: OS X 10.14.6 (Mojave) VS Code Version: 1.41.1 C/C++ Extension Version: 0.26.2

Conditions

  1. pull Electron (I mean entire Electron) sources and add them as a folder to Workspace
  2. open multiple .h or .cpp files
  3. wait a few minutes (you don't even need to type anything or use intellisense actively)

Issue Microsoft.VSCode.CPP.IntelliSense.Msvc.darwin and Microsoft.VSCode.CPP.Extension.darwin processes start to consume roughly 50% of CPU each, and this never ends.

At first I thought that this is just because of indexing or otherwise caching, and tried to just wait - but It didn't help. It can be like that for hours, I never saw that these processes stop consuming so much CPU. This does really hinder my work and I had to disable CPP plugin completely for this workspace.

Please help, thx.

Снимок экрана 2020-01-13 в 19 13 11

jphw avatar Jan 13 '20 16:01 jphw

@jphw , can you share the language server logs of the issue occurring? Perhaps the logs will show the work happening in the processes.

michelleangela avatar Jan 15 '20 19:01 michelleangela

Are you referring to the https://github.com/electron/electron repo? I just cloned it on my MacBook and didn't have any trouble with version 0.26.2 (or 0.26.3 insiders). About 1800 files are tag parsed and the extension made quick work of it.

Please confirm the repo and also turn on logging as @michelleangela suggested and we can take a further look.

bobbrow avatar Jan 15 '20 20:01 bobbrow

Similar issue here when loading Bitcoin Core repo and opening a couple of files. CPU load ranges between 30% and 99% RAM consumption is also very high (around 3GB between cpptools and cpptools-srv) The same behavior happens on three different devices (one desktop and two laptops), all with Ubuntu 18.04.

UPDATE: CPU/RAM load seems to drop after some minutes (around 10 in my case). I assume this has to do with the parsing of large projects. I made another test with a folder where I have several repos and the same thing happened: very high cpu loads during several minutes and then dropped. After the first time, the same thing happens every time I open the same workspace, but only lasts 1 or 2 minutes.

fed-franz avatar Apr 09 '20 14:04 fed-franz

@frz-dev, what you describe is the expected behavior. You can't use features like goto definition until we've parsed through your code. It should only happen when you open the folder for the first time. If you want to slow it down and spread the CPU usage over a longer time, you can configure this with the "C_Cpp.workspaceParsingPriority" setting.

bobbrow avatar Apr 09 '20 17:04 bobbrow

@bobbrow I see the C/C++ extension using a full core all the time on all repos and PCs. It doesn't matter how long it has run for. It just never stops using a core. I think might be tracked in another issue.

BillDenton avatar Apr 09 '20 17:04 BillDenton

I actually had this issue some time ago on other devices and didn't test if it was temporary. Since it was basically freezing the whole system (both on laptop and desktop), I just decided to remove the extension. I don't know if on those devices the behavior was going to be the same.

All I can say is that affecting a whole system shouldn't be an "expected behavior"... And if it is, the user should be warned about it before to proceed. Maybe showing a progress bar or something.

fed-franz avatar Apr 10 '20 17:04 fed-franz

@BillDenton if you have repro steps that we can follow, we'd love to get to the bottom of the issue, though I'd like to open a new issue for it if it's not being tracked anywhere else.

@frz-dev The main process should only be using a single core. I just cloned bitcoin and verified the extension only uses 1 core for just under 2 minutes. It doesn't affect the whole system unless maybe you've got an older machine with fewer cores available. Is that the case for you? Opening source files spikes the CPU for a few seconds while we compile the file, but otherwise, I'm not seeing any issues with that repo.

bobbrow avatar Apr 10 '20 22:04 bobbrow

I could see 2 cores used. The machine is quite new (i5 8th gen, 8gb ram), as well as the other two ones I had trouble with (unfortunately I cannot access theme right now because of the confinement).

One thing I noticed is that the 'mount' process was also consuming a lot of CPU. I don't know how that works (I thought mount was only invoked when mounting the partition), but the performance might be affected by the fact that the repo is stored on a NTFS partition (?).

The other thing I think affects my system the most is the amount of memory used by the cpp extension (around 2GB). Is this normal?

EDIT: after working a little the RAM consumption went up to 4GB. I believe this is not a normal behavior. Should I open a new issue?

EDIT2: found this: #4119 . Installing the 0.26.2-insiders version solved the issue

fed-franz avatar Apr 11 '20 13:04 fed-franz

@frz-dev What version did you have before? 0.27.0 is newer and should also have the fix. The issue https://github.com/microsoft/vscode-cpptools/issues/4119 is about cpptools-srv memory usage and not cpptools? Which process is using high memory?

sean-mcmanus avatar Apr 13 '20 19:04 sean-mcmanus

Actually, after some use, I noticed that the problem also occurs with the insider version. Updating to 0.27.0 does not seem to solve it either.

The process using most RAM is Microsoft.VSCode.CPP.IntelliSense.Msvc.linux with 0.26.2-insiders and cpptools-srv with 0.27

A screenshot of htop: https://ibb.co/mXY2Y0W

fed-franz avatar Apr 14 '20 10:04 fed-franz

@frz-dev, to be clear, I was saying that the main process cpptools uses one core. Each of the cpptools-srv processes will use up to another core, but those are usually in short bursts instead of a sustained high usage on startup like the main process.

You screenshot shows higher Virtual memory usage, but relatively normal Resident memory usage (<1 GB ). cpptools-srv generally has high virtual memory usage because it maps a precompiled header database which is intended to save you CPU usage as you use IntelliSense while editing files. This does not mean it is actually consuming that memory. It is just using address space. In other words, I see no cause for alarm based on the screenshot you shared.

bobbrow avatar Apr 14 '20 17:04 bobbrow

I believe the total amount of memory occupied by all cpptools processes is much higher. I cannot find a proper way to calculate the amount of memory actually occupied including all cpptools and cpptools-srv processes. Each method I try gives different (and often unrealistic) results...

But as an example, I just made a quick test by looking at htop. By disabling the cpptools extension, the "Mem" bar went from 6.87GB to 4.92GB, which makes me think that the actual amount of memory used by cpptools was around 2GB approx.

Either way, resident memory of cpptools and cpptool-srv combined is constantly above 1GB.

fed-franz avatar Apr 15 '20 16:04 fed-franz

@frz-dev That sounds like normal behavior if the workspace and translation units are sufficiently large.

sean-mcmanus avatar Apr 15 '20 18:04 sean-mcmanus

I see. I guess I'll have to live with that (or look for more efficient alternatives). Still believe 2GB it's an excessive amount of memory for 24MB of sources (of which I only use a small fraction)

fed-franz avatar Apr 15 '20 22:04 fed-franz

Closing this issue as it appears there are no remaining actionable items related to CPU usage. If you continue to have CPU usage problems, please open a new issue and we can discuss further.

bobbrow avatar Apr 29 '20 21:04 bobbrow