microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.68k stars 29.45k forks source link

Very high CPU and memory usage after update in MacOS Big Sur #112393

Closed tapz closed 3 years ago

tapz commented 3 years ago

Steps to Reproduce:

  1. Start vscode

Does this issue occur when all extensions are disabled?: Yes

After updating vscode it started to eat all cpu time of all 4 cores for about 10 minutes after restarting vscode. After that it eats 150% of total cpu time forever. What is it doing and can't it just use one core and not freeze the whole machine? Also, why does it eat all cpu time when there is an update waiting for restart?

Also, vscode uses 12 to 18GB of RAM. That's a lot of bytes when thinking how many characters of code I have. What kind of neural network is it building in memory?

After restart:

[Version:          Code 1.52.0 (940b5f4bb5fa47866a54529ed759d95d09ee80be, 2020-12-10T22:46:53.673Z)
OS Version:       Darwin x64 20.1.0
CPUs:             Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz (8 x 2300)
Memory (System):  32.00GB (0.30GB free)
Load (avg):       383, 140, 82
VM:               0%
Screen Reader:    no
Process Argv:     --crash-reporter-id c6ff1644-c7b5-4b8a-929c-28debafc7206
GPU Status:       2d_canvas:                  enabled
                  flash_3d:                   enabled
                  flash_stage3d:              enabled
                  flash_stage3d_baseline:     enabled
                  gpu_compositing:            enabled
                  metal:                      disabled_off
                  multiple_raster_threads:    enabled_on
                  oop_rasterization:          enabled
                  opengl:                     enabled_on
                  protected_video_decode:     unavailable_off
                  rasterization:              enabled
                  skia_renderer:              disabled_off_ok
                  video_decode:               enabled
                  webgl:                      enabled
                  webgl2:                     enabled

CPU %   Mem MB     PID  Process
    3      131   49538  code main
   32       98   49544     gpu-process
    0       33   49548     utility
    2      229   49549     window (MyApp1 (Workspace))
   94      197   49594       extensionHost
    0      131   49928         electron_node tsserver.js 
    0      164   49929         electron_node tsserver.js 
    0       66   50062           electron_node typingsInstaller.js typesMap.js 
   30       98   50326             npm
    0       33   49955         electron_node languageserver.js 
    0       98   50146         electron_node eslintServer.js 
    0       66   49636       watcherService
    2      229   49552     window (MyApp2 (Workspace))
    3       98   49590       extensionHost
    0       98   49799         electron_node tsserver.js 
    0      229   49800         electron_node tsserver.js 
    1       66   49920           electron_node typingsInstaller.js typesMap.js 
    0       33   49817         /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=49590
    0       33   49818         electron_node languageserver.js 
    0       98   49983         electron_node eslintServer.js 
    0       33   49629       watcherService
    2      229   49553     window (MyApp3 (Workspace))
    2       98   49584       extensionHost
    0       98   49713         electron_node tsserver.js 
   27      393   49714         electron_node tsserver.js 
    0       66   49803           electron_node typingsInstaller.js typesMap.js 
    0       33   49731         electron_node languageserver.js 
    0       98   49879         electron_node eslintServer.js 
    0       33   49625       watcherService
    2      229   49554     window (MyApp4 (Workspace))
    4      131   49592       extensionHost
    0       98   49966         electron_node tsserver.js 
   29      295   49969         electron_node tsserver.js 
    0       66   50094           electron_node typingsInstaller.js typesMap.js 
    0       33   49987         /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=49592
    0       33   49989         electron_node languageserver.js 
    0      131   50173         electron_node eslintServer.js 
    0       33   49635       watcherService
    2      229   49556     window (MyApp5 (Workspace))
    3       98   49586       extensionHost
    0       98   49826         electron_node tsserver.js 
   54      360   49828         electron_node tsserver.js 
    0       66   49960           electron_node typingsInstaller.js typesMap.js 
    0       33   49866         electron_node languageserver.js 
    0       98   50033         electron_node eslintServer.js 
    0       33   49633       watcherService
    1      229   49557     window (MyApp6 (Workspace))
    8       98   49593       extensionHost
    0       98   50086         electron_node tsserver.js 
   33      262   50087         electron_node tsserver.js 
    0       66   50175           electron_node typingsInstaller.js typesMap.js 
    0       33   50113         electron_node languageserver.js 
    0      131   50206         electron_node eslintServer.js 
    0       33   49637       watcherService
    3      229   49558     window (MyApp7 (Workspace))
    2       98   49585       extensionHost
    0      131   49794         electron_node tsserver.js 
   39      393   49796         electron_node tsserver.js 
    0       66   49917           electron_node typingsInstaller.js typesMap.js 
    0       33   49807         electron_node languageserver.js 
    0      131   50015         electron_node eslintServer.js 
    0       33   49627       watcherService
    4      197   49560     window (MyApp8 (Workspace))
    1       98   49588       extensionHost
    0       98   49814         electron_node tsserver.js 
   26      393   49815         electron_node tsserver.js 
    0       66   49948           electron_node typingsInstaller.js typesMap.js 
    0       33   49830         electron_node languageserver.js 
    0       98   50055         electron_node eslintServer.js 
    0       33   49632       watcherService
    1      197   49561     window (MyApp9 (Workspace))
    1       98   49587       extensionHost
    0       98   49668         electron_node tsserver.js 
   25      393   49669         electron_node tsserver.js 
    6       66   49754           electron_node typingsInstaller.js typesMap.js 
    0       33   49676         electron_node languageserver.js 
    0       98   49787         electron_node eslintServer.js 
    0       33   49624       watcherService
    2      229   49562     window (MyApp10 (Workspace))
    1       98   49582       extensionHost
    0       98   49694         electron_node tsserver.js 
   31      393   49697         electron_node tsserver.js 
    0       33   49785           electron_node typingsInstaller.js typesMap.js 
    0       33   49704         electron_node languageserver.js 
    0       33   49762         /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=49582
    0       98   49865         electron_node eslintServer.js 
    0       33   49630       watcherService
    0      229   49563     window (MyApp11 (Workspace))
    1       98   49589       extensionHost
    0       98   49677         electron_node tsserver.js 
   41      393   49678         electron_node tsserver.js 
    0       66   49763           electron_node typingsInstaller.js typesMap.js 
    0       33   49692         /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=49589
    0       33   49693         electron_node languageserver.js 
    0       98   49804         electron_node eslintServer.js 
    0       33   49623       watcherService
    2      229   49564     window (MyApp112 (Workspace))
    1      131   49591       extensionHost
    0      131   49964         electron_node tsserver.js 
   23      295   49965         electron_node tsserver.js 
    0       66   50091           electron_node typingsInstaller.js typesMap.js 
    0       33   49980         electron_node languageserver.js 
    0      131   50167         electron_node eslintServer.js 
    0       33   49631       watcherService
   28      131   49578     shared-process
    0        0   50380       /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=](url)

After the first 10 minutes:

CPU %   Mem MB     PID  Process
    1       98   45181  code main
    6       98   45192     gpu-process
    0       33   45197     utility
    1      131   45200     window (MyApp1 (Workspace))
   65       98   45246       extensionHost
    0       98   45657         electron_node tsserver.js 
    0      229   45659         electron_node tsserver.js 
    0       66   45760           electron_node typingsInstaller.js typesMap.js 
    0       33   45667         electron_node languageserver.js 
    0       66   45793         electron_node eslintServer.js 
    0       33   45296       watcherService
vscodebot[bot] commented 3 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

tapz commented 3 years ago

It's now been like this for the past 8 hours. Luckily, it's only MyApp1 (a React Native app, others are node.js server apps).

Screenshot 2020-12-13 at 22 53 52
alexdima commented 3 years ago

Out of 12 extension hosts, one has high CPU usage. There appears to be much more "consistent" high CPU usage in the tsserver processes, so leaving to @mjbvz to investigate.

tapz commented 3 years ago

Now, when I close the RN project vscode is using a lot of cpu time for this:

97      98   54993     shared-process
 0       0   68493       /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
tapz commented 3 years ago

Is there any workaround for this? I'm getting tired of listening the fan of my MacBook.

alexdima commented 3 years ago

cc @deepak1556 @bpasero

mjbvz commented 3 years ago

@tapz Can you share the project that causes this?

tapz commented 3 years ago

@mjbvz Not the source code. But package.json yes.

viktorianer commented 3 years ago

I am not tapz, but can share 2 really micro projects, I use with my students, causes same issues.

First is tiny, only 134 LOC, 24 642 files (18 653 files in node_modules only), and causes already ~15 - 25 % CPU load on my macOS Big Sur. https://bitbucket.org/viktorianer/sample-app

Second is small, only 746 LOC, 21 716 files (16 002 files in node_modules only), and causes already ~25 - 40 % CPU load. https://github.com/viktorianer/rails-community-app

The third project, I can not share, it is for my organization only. It has 35 660 LOC, 439 910 files without any files in node_modules folder, and causes ~350 - 500 % CPU load! You cannot work on this project with VS Code.

Running all 3 project together can take down my MacBook Pro (6-Core Intel i7!):

Screenshot 2020-12-15 at 09 14 21

tapz commented 3 years ago
{
  "name": "abc",
  "author": "Abc",
  "homepage": "http://www.abc.com",
  "version": "1.2.3",
  "private": true,
  "scripts": {
    "eslint": "./node_modules/eslint/bin/eslint.js src/",
    "metro": "react-native start --reset-cache",
    "start": "cd android && ./gradlew clean && cd - && react-native run-android --variant=abcDebug",
    "test": "$(npm bin)/mocha --opts ./test/mocha.opts",
    "bundle": "react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/",
    "release-android": "cd android && ./gradlew clean && yarn bundle && ./gradlew assembleAbcRelease --scan && cd -",
    "install-android": "cd android && ./gradlew installAbcRelease && cd -",
    "postinstall": "npx jetify node && node ./fixNodeModulesForXCode12.js",
    "clear": "rm -rf ~/.gradle/caches/ && watchman watch-del-all && rm -rf android/.gradle && rm -rf android/build && rm -rf android/app/build && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-* && rm -rf node_modules && rm yarn.lock && yarn"
  },
  "dependencies": {
    "@react-native-community/masked-view": "0.1.10",
    "@react-navigation/native": "5.8.10",
    "@react-navigation/stack": "5.12.8",
    "@sentry/react-native": "2.1.0",
    "axios": "0.21.0",
    "format-duration": "1.3.1",
    "google-libphonenumber": "3.2.15",
    "i18n-js": "3.8.0",
    "langs": "2.0.0",
    "moment": "2.29.1",
    "prop-types": "15.7.2",
    "react": "17.0.1",
    "react-mixin": "5.0.0",
    "react-native": "0.63.4",
    "react-native-animatable": "1.3.3",
    "react-native-calendario": "2.1.1",
    "react-native-date-picker": "3.2.5",
    "react-native-device-info": "7.3.1",
    "react-native-gesture-handler": "1.9.0",
    "react-native-gifted-chat": "0.16.3",
    "react-native-image-crop-picker": "0.35.2",
    "react-native-indicators": "0.17.0",
    "react-native-languages": "3.0.2",
    "react-native-localize": "2.0.1",
    "react-native-orientation-locker": "1.2.0",
    "react-native-reanimated": "1.13.2",
    "react-native-safe-area-context": "3.1.9",
    "react-native-scalable-image": "1.0.0",
    "react-native-screens": "2.16.1",
    "react-native-vector-icons": "7.1.0",
    "react-native-video": "5.0.2",
    "react-native-webview": "11.0.2",
    "react-timer-mixin": "0.13.4"
  },
  "devDependencies": {
    "@babel/cli": "7.12.10",
    "@babel/core": "7.12.10",
    "@babel/runtime": "7.12.5",
    "@react-native-community/eslint-config": "2.0.0",
    "babel-eslint": "10.1.0",
    "babel-plugin-transform-es2015-constants": "6.1.4",
    "babel-plugin-transform-remove-console": "6.9.4",
    "babel-polyfill": "7.0.0-beta.3",
    "babel-register": "7.0.0-beta.3",
    "eslint": "7.15.0",
    "eslint-plugin-babel": "5.3.1",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-react": "7.21.5",
    "eslint-plugin-react-native": "3.10.0",
    "jetifier": "1.6.6",
    "metro-react-native-babel-preset": "0.64.0",
    "react-dom": "17.0.1"
  }
}
marrrc commented 3 years ago

I am too seeing this behaviour with extensionHost CPU usage after upgrade to Big Sur and on Insiders Build Verson 1.53.0. Type of project doesn't matter for me, with an amount of ~10k files CPU used is already at around 25%, with ~20k files it ramps up to >35%, and finally a project with ~45k files eating up 115%.

mjbvz commented 3 years ago

@tapz Do you see this if you just use that package.json in a new project with a single js file?

robipop22 commented 3 years ago

@mjbvz I have the same problems, fans are going crazy on React Native projects mostly. I have another project which is a TS package, that works fine VSCode is using around 20% cpu, but for the RN projects the CPU usage is ~ 120%. I have 2 RN projects, one is using TS and one it is not, but the CPU usage is the same. (~120%).

I also created a new folder, created a package.json and put there all the content from a RN Project and a single index.js file. In the index.js file I put the content from the RN project again the CPU usage is around ~10% or ~20-30 sometimes, which I think is fine.

Note: this cpu usage only happened after updating to macos Big Sur, the respective projects did not encounter any issues before.

Macos specs:

Screenshot 2020-12-16 at 10 20 58
dzhgenti commented 3 years ago

Hey guys, I have the same problem on macOS Catalina after upgrading to 1.52.0.

Process: image

OS: image

VS Code:

1.52.0
940b5f4bb5fa47866a54529ed759d95d09ee80be
x64
viktorianer commented 3 years ago

Switch back to older Version 1.51 does not help! 👎

deepak1556 commented 3 years ago

@mjbvz do we have a way to attach remote debugging to TS server process ? We have inspect-extensions and inspect-brk-extensions that mock nodejs inspect, inspect-brk flags for extension host process. If we can add similar flags to the TS server process then we can inspect them from any debugger and take a CPU profile to understand whats happening here.

deepak1556 commented 3 years ago

For users who are seeing high CPU usage on the extension host process and not TS server process, can you take a CPU profile following these steps.

* Launch code with `--inspect-extensions=9229`
* In chrome browser visit `chrome://inspect` or in edge browser visit `edge://inspect`
* You should an entry under `Remote Target` that starts with `/Applications/Visual Studio Code/....`
* If you don't see the above entry, then
  * Under `Devices`, click `open dedicated devtools for node`
  * Under `Connection` tad, add `localhost:9229`
  * You should now see the target
* Click inspect
* Go to `profiler` tab and start a profile
* Take 1 or 2 profiles during the high CPU phase and attach them here.
dzhgenti commented 3 years ago

Just tried to use the profiler. But nothing pops-up in the Profiler tab:

image

Tried on the project with lots of files and a small one with just a couple of files. The profiler didn't show anything in both cases.

deepak1556 commented 3 years ago

that is a bug in chrome https://bugs.chromium.org/p/chromium/issues/detail?id=1151855, can you try with chrome canary https://www.google.com/chrome/canary/

lihuanshuai commented 3 years ago

i got ~180% cpu in my python workspace

CPU-20201217T121730.cpuprofile.zip

kennir commented 3 years ago

I have the same problem, Code helper (render) process > 230% CPU in a single python file.

macOS big sur Macbook Pro 16"

deepak1556 commented 3 years ago

@lihuanshuai thanks for the profile, from the capture it shows most of the time is spent in (program) stack which would be native call sites.

As a next step I would like to capture v8 profile by starting the extension host process with --prof flag. @alexdima is there way to pass flags to extension host process start ? The flag will record both native and javascript stacks https://v8.dev/docs/profile

viktorianer commented 3 years ago

I do not know how to start it in FF or Safari (Chrome is not working), but VS Code has own DevTools...it shows me:

localProcessExtensionHost.ts:258 Debugger attached.
log.ts:191  WARN UNRESPONSIVE extension host, 'ecmel.vscode-html-css' took 91% of 9610.665ms, saved PROFILE here: '/var/folders/3m/qxc1ghr16z9fqx6y_rvh6n_h0000gq/T/exthost-a380f8.cpuprofile' 
Array(4)
0: {id: "ecmel.vscode-html-css", total: 8699432, percentage: 91}
1: {id: "gc", total: 395109, percentage: 4}
2: {id: "program", total: 228012, percentage: 2}
3: {id: "self", total: 287924, percentage: 3}
length: 4
__proto__: Array(0)

exthost-a380f8.cpuprofile.zip

I do not know how to start it with --prof, sorry. Just tried it with:

code . --inspect-extensions=9229 --prof

Results in... :

WARN UNRESPONSIVE extension host, 'ecmel.vscode-html-css' took 96% of 1834.304ms, saved PROFILE here: '/var/folders/3m/qxc1ghr16z9fqx6y_rvh6n_h0000gq/T/exthost-ad797b.cpuprofile' 
(13) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id: "ban.spellright", total: 2342, percentage: 0}
1: {id: "CoenraadS.bracket-pair-colorizer", total: 7658, percentage: 0}
2: {id: "ecmel.vscode-html-css", total: 1751783, percentage: 96}
3: {id: "formulahendry.auto-rename-tag", total: 335, percentage: 0}
4: {id: "gc", total: 33772, percentage: 2}
5: {id: "Gruntfuggly.todo-tree", total: 4053, percentage: 0}
6: {id: "mechatroner.rainbow-csv", total: 128, percentage: 0}
7: {id: "mtxr.sqltools", total: 279, percentage: 0}
8: {id: "program", total: 6893, percentage: 0}
9: {id: "self", total: 24371, percentage: 1}
10: {id: "streetsidesoftware.code-spell-checker", total: 525, percentage: 0}
11: {id: "vscode.git", total: 744, percentage: 0}
12: {id: "vscode.github-authentication", total: 1344, percentage: 0}
length: 13
__proto__: Array(0)

Archive.zip

I hope it helps...

Process Explorer:

CPU %   Memory (MB) PID Name
9   98  68625   code main
13  49  68639        gpu-process
0   16  68657        utility
46  180 68699        window (geocoder.rb — moviepilot.de)
119 541 68824            extensionHost
42  16  68853                /Users/viktorianer/.rbenv/versions/2.6.6/bin/ruby /Users/viktorianer/.rbenv/versions/2.6.6/bin/solargraph socket --port 0
0   33  68947                electron_node server.js 
0   16  68973                electron_node serverMain.js 
0   33  68974                electron_node languageserver.js 
89  98  68975                /Users/viktorianer/.rbenv/versions/2.6.6/bin/rake routes
0   33  68999                electron_node server.js 
0   0   69102                /usr/local/bin/git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname)
161 147 68845            watcherService
0   16  68847            searchService
0   82  68846        shared-process
3   262 69086        window
0   49  69105        window (Process Explorer)
0   0   69124        /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
andrewmacp commented 3 years ago

I'm on MacOS Catalina (10.15.7) and have also been seeing very high CPU usage by the "Code Helper (Renderer)" process since upgrading to 1.52.1 this morning. In a relatively large project it's consistently using ~400% CPU as shown in the Activity Monitor and also the Process Explorer, where all CPU usage is attributed to "extensionHost".

I ran dtruss against the Code Helper process and can see that it's constantly calling stat64() on every folder in the project structure. In a tiny test project with a couple of folders it appears to be calling stat64() once per second on each folder. On a larger project (hundreds/thousands of folders) it's just constantly stat64-ing everything over and over again. Is this expected?

deepak1556 commented 3 years ago

@viktorianer thanks for the profile, but in your case the high cpu usage is from ecmel.vscode-html-css extension, all the profiles point to the calls from the extension, you would want to report the issue there.

@andrewmacp can you provide the cpu profile for those processes.

dzhgenti commented 3 years ago

@deepak1556, thanks for looking into this issue. Apparently, vscode-html-css was the root cause of the CPU issue. A few hours ago an update for this extension arrived https://github.com/ecmel/vscode-html-css/issues/191, and CPU usage went down to normal level.

Thanks to everyone for troubleshooting and prompt replies. Cheers!

alexdima commented 3 years ago

As a next step I would like to capture v8 profile by starting the extension host process with --prof flag. @alexdima is there way to pass flags to extension host process start ? The flag will record both native and javascript stacks https://v8.dev/docs/profile

@deepak1556 There is no way at the moment. But I would like to add support for this if possible. Here is where the extension host process is started, what do you have in mind? Something like a --prof-extensions which would add --prof to the argv there ?

robipop22 commented 3 years ago

@deepak1556 update to the html-css extension did the trick code renderer is now ~10% related issue

Thanks for the prompt response and thanks @dzhgenti for pointing this out.

deepak1556 commented 3 years ago

Something like a --prof-extensions which would add --prof to the argv there ?

@alexdima yup thats exactly what I need, maybe --prof-v8-extensions naming would be better. This should create the v8 sample logs for the process.

alexdima commented 3 years ago

@deepak1556 I've scaffolded that in #112777 but when I run locally scripts\code-cli.bat --prof-v8-extensions, even if I see the --prof flag on the extension host process, I don't notice anything special, like where does the v8 profile output go to?

image

jrieken commented 3 years ago

@alexdima Don't we already support extension host profiling via the Running Extensions view? Like F1 > Show Running Extensions > Start Extension Host Profile

alexdima commented 3 years ago

@jrieken Yes, and we received a CPU profile, but all the time is spent in "(program)". If I understood correctly, @deepak1556 was asking to launch the extension host with --prof which would record both native and js stacks.

jrieken commented 3 years ago

oh, now I understand. Thanks for clarifyiing

viktorianer commented 3 years ago

@viktorianer thanks for the profile, but in your case the high cpu usage is from ecmel.vscode-html-css extension, all the profiles point to the calls from the extension, you would want to report the issue there.

Yeh, thank you! They just updated this plugin! https://github.com/ecmel/vscode-html-css/issues/191

Now the CPU is short time over 200%, but after ~10 seconds it has only ~20%. 👍 Thank you for support!

lihuanshuai commented 3 years ago

my vscode-html-css extension is now 1.2.0, and the cpu problem has gone

tapz commented 3 years ago

I added node_modules to Commonly Used - Files: Exclude and now the CPU usage is back to normal (6 to 10% of one core).

jrieken commented 3 years ago

Likely file watching then. fyi @bpasero

bpasero commented 3 years ago

No, nothing in https://github.com/microsoft/vscode/issues/112393#issue-765353545 hints to watcherService, but possibly TypeScript runs their own watcher?

mjbvz commented 3 years ago

@tapz Do you see this problem if you use just the package.json you shared in a new project with a single js file?