microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.46k stars 1.53k forks source link

cpptools takes hours of CPU time per day for a project which compiles in 5 seconds #5574

Open MSoegtropIMC opened 4 years ago

MSoegtropIMC commented 4 years ago

Type: LanguageService

Describe the bug

For every C++ project, even tiny ones which compile in a few seconds, a cpptools process runs for something between 6 and 40 minutes every time I open the project and also from time to time after editing or git operations. Over the day this accumulates to many hours and estimated about 25% of the time my laptop fan runs cause of cpptools (it hardly every runs cause of compiles). Also the memory consumption of cpptools is fairly high - around 7GB is common. I guess this has to do with scanning system headers, but is still seems wasteful to spend 30 minutes on symbol analysis for a project where a release build takes 5 seconds. This is not really a bug, but to me it looks like unnecessary waste of resources.

One more observation: when I delete the folder in which VSCode keeps the database (on Mac ~/Library/Application Support/VSCodium/User/workspaceStorage/) it runs the first time "only" for 6 minutes - Intellisense is fully operational. The second time it decides to run for the same projects - about 1 hour later - it runs for 29 minutes.

Steps to reproduce

Expected behavior

In case you cannot reproduce this (for me this happens for every C++ project every time since at least 6 months) I can of cause provide logs, a sample project and gprof statistics.

chenhengqi commented 3 years ago

@sean-mcmanus There are many [unknown]s. May be compiled with -g -O0 would help.

sean-mcmanus commented 3 years ago

Yes, the binary is a Release and not Debug binary, but we haven't seen that block call stack or performance analysis so far, because all the important call stack frame info should still exist (from the cases we've seen so far). Can you ignore the "unknowns" and determine which known call stack frames are contributing the most to the CPU issue?

chenhengqi commented 3 years ago

I will have a try.

leifwalsh commented 3 years ago

I'm not sure if this is a similar problem to what's being discussed here, but this thread seems more recently active than #6149, so here's a link to some diagnostic info I've observed and captured: https://github.com/microsoft/vscode-cpptools/issues/6149#issuecomment-817005519

chenhengqi commented 3 years ago

For those who come to this issue, here is a simple solution on linux:

https://github.com/chenhengqi/put-cpptools-in-prison

The problem dates back to years ago, I don't know why it never been solved.

kiiv-cz commented 3 years ago

I started to experience this issue about week ago (current version was 1.3.1 for this extension). After some time since vscode starts db icon shows parsing files, then load stops. However when I start editing c++ file (simple click into it is enough), it starts "parsing opened files" and it never ends.

Now I downgraded version to 1.2.2 and there is no issue with excessive load.

It might not be related to the original issue (whole project is much bigger)

romanholidaypancakes commented 3 years ago

image

maartenaudiotelligence commented 3 years ago

I was able to solve this in my case by simply deleting the .vscode folder in my project directory.

miqmago commented 2 years ago

In my case this is happening every time I open a project with .vscode/c_cpp_properties.json. I've been searching the intelli sense cache database file in $HOME/Library/Caches/vscode-cpptools but there is nothing in this folder:

$ ll  $HOME/Library/Caches/vscode-cpptools
total 0

This happens each time I open a c++ project, the fan start to run, it turns really hot and my laptop seems ready to take off... If I open two c++ projects at the same time, two cpptools processes are launched.

After those 20-60 minutes of 100% CPU usage, it calms down and after some time then intellisense starts to work. It works all the time along that I have vscode opened, but when I shutdown and open again it starts the same process.

I can't see any db icon on the bottom bar.

C/C++: v1.8.4 osx: 11.2.3

rustyx commented 2 years ago

Any update on this? Opening Linux kernel in vscode results in 100% CPU usage forever. It seems to be impossible to develop Linux kernel using vscode at the moment.

sean-mcmanus commented 2 years ago

@rustyx You're most likely hitting https://github.com/microsoft/vscode-cpptools/issues/6454 , see my comment https://github.com/microsoft/vscode-cpptools/issues/6454#issuecomment-1030302455 for how to diagnose and workaround the issue.

biodranik commented 2 years ago

Any workarounds or solutions for Mac OS X?

cpptools and cpptools-srv consume a lot of CPU for hours in our project: https://github.com/organicmaps/organicmaps/ Is there a configuration option to exclude some paths from parsing?

kiiv-cz commented 2 years ago

I'm using files.exclude in settings.json Something like:

    "files.exclude": {
        "/bin": true,
        "/boot": true,
        "/cdrom": true,
        "/dev": true,
        "/proc": true,
        "/etc":true,

and it seems the -I/ seems not to be an issue anymore (at least one down)

sean-mcmanus commented 2 years ago

@biodranik Yeah, C_Cpp.files.exclude (or files.exclude)...folder excludes are preferred, otherwise you may need to change C_Cpp.exclusionPolicy.