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

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

Open MSoegtropIMC opened this issue 6 years ago • 64 comments

Type: LanguageService

Describe the bug

  • OS and Version: OSX 10.15.4
  • VS Code Version: 1.45.1
  • C/C++ Extension Version: 0.28.1

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

  • Open any project with C files
  • Look at the CPU time of the cpptools process

Expected behavior

  • cpptools needs less than 10x the compile time

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.

MSoegtropIMC avatar May 27 '20 09:05 MSoegtropIMC

Any updates on if this can be fixed? I've been searching a long time for a solution. IntelliSense finds over 5 million files. LOL.

Setting "C_Cpp.default.browse.path" does not work, because this does not limit which files it scans. Setting "files.exclude does not work, because this removes my ability to see build output folders in VSCode.

I want to exclude the build output folders from the cpptools scanning.

I'm on Mac 10.15.7, VSCode 1.53.2, IntelliSense v1.2.2-insider. My build system is Bazel, and my workspace contains the repo root.

I've seen the previous messages about symlinks, and this is probably the problem, since Bazel produces symlinks for the build output folders. Therefore, I would be fine just telling Intellisense to ignore them, so it will stop following the symlinks and thinking there is 5 million files to scan.

fyta2000 avatar Feb 18 '21 09:02 fyta2000

@fyta2000 We're working making files.exclude work during the file scanning phase (https://github.com/microsoft/vscode-cpptools/issues/3123) -- if that fixes your issue, we could also consider adding some additional parse.exclude setting.

sean-mcmanus avatar Feb 18 '21 18:02 sean-mcmanus

I'm experiencing this in my linux development VM for https://github.com/dotnet/runtime, running a VS Code client on Windows connected to the linux host (so cpptools runs on the linux host along with some node processes, while the UI runs outside of the linux host). Has any testing happened with that repo for this issue? It does seem to be much worse during builds, which is confusing because I got the impression that vscode takes gitignore into account for these things like it does for project-wide search and build artifact directories are ignored.

When I checked in and opened top, cpptools' cpu time total was around 65 hours, with xorg and konsole at 23 and 21 hours and node (probably the cpptools parent?) at 19. cpptools also was using about half a gig of memory (2.4g virtual).

kg avatar Mar 05 '21 10:03 kg

@fyta2000 We're working making files.exclude work during the file scanning phase (#3123) -- if that fixes your issue, we could also consider adding some additional parse.exclude setting.

OK, so what I tried was to add the bazel build output symlink paths to the "files.exclude", and this seems to mitigate the issue. However, I do want to see these output paths in my workspace, so I can see the outputs of my build (generated code, build artifacts, etc.).

So, just more FYI, my build output paths will look like /bazel-*/. These are just symlinks to somewhere else. But, some of these symlinks contain symlinks, and we end up with cpptools thinking there are a millions of files. Maybe cpptools could resolve the paths, so symlink paths are removed, then it should be able to realize it's already gone down a certain path.
For now, what I did was add to "files.exclude" and entry like this: "**/bazel-testlogs/**/bazel-*/" : true,, so that the recursive symlink paths get removed from this particular symlink path.

fyta2000 avatar Mar 06 '21 03:03 fyta2000

@fyta2000 To see the output paths in your workspace, you can add it to a separate workspace folder that has C_Cpp.default.browse.path = [].

However, FYI, we haven't implemented the files.exclude handling in the scanning phase yet, but it should avoid any extra tag parsing later on.

sean-mcmanus avatar Mar 06 '21 03:03 sean-mcmanus

Is cpptools itself open-sourced ?

chenhengqi avatar Mar 13 '21 07:03 chenhengqi

I also suffer this problem frequently.

Here is an output of the BCC tool profile tracing the cpptools process.

cpptools.profile

chenhengqi avatar Mar 13 '21 07:03 chenhengqi

@chenhengqi cpptools is not open source. Are you able to analyze the profile data to determine which call stack is causing the problem? I'm not familiar with the BCC tool.

sean-mcmanus avatar Mar 15 '21 19:03 sean-mcmanus

@sean-mcmanus I've tried on linux, but it seems some symbols are optimized out.

chenhengqi avatar Mar 16 '21 00:03 chenhengqi

@chenhengqi What you do mean by "optimized out"? They symbols for call stacks should be available on Linux without much being optimized out. I see the call stacks in your cpptools.profile.

sean-mcmanus avatar Mar 16 '21 06:03 sean-mcmanus

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

chenhengqi avatar Mar 16 '21 06:03 chenhengqi

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?

sean-mcmanus avatar Mar 16 '21 20:03 sean-mcmanus

I will have a try.

chenhengqi avatar Mar 16 '21 22:03 chenhengqi

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

leifwalsh avatar Apr 09 '21 22:04 leifwalsh

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.

chenhengqi avatar Apr 10 '21 00:04 chenhengqi

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)

kiiv-cz avatar Apr 20 '21 12:04 kiiv-cz

image

romanholidaypancakes avatar May 17 '21 14:05 romanholidaypancakes

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

maartenaudiotelligence avatar Jul 21 '21 10:07 maartenaudiotelligence

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

miqmago avatar Feb 13 '22 20:02 miqmago

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.

rustyx avatar Mar 08 '22 11:03 rustyx