microsoft / vscode

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

Electron uses too much CPU on macOS #142828

Closed vmatyus closed 2 years ago

vmatyus commented 2 years ago

Issue Type: Bug

Steps to Reproduce:

  1. Start VSCode
  2. Navigate to Source Control plane

The CPU usage of Electron process goes up to 99% and stays there. It also not detects the git repository and requests for Initialize Repository

VS Code version: Code 1.64.2 (f80445acd5a3dadef24aa209168452a3d97cc326, 2022-02-09T22:00:58.347Z) OS version: Darwin x64 20.6.0 Restricted Mode: No

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (16 x 2300)| |GPU Status|2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled| |Load (avg)|3, 3, 4| |Memory (System)|16.00GB (0.25GB free)| |Process Argv|--crash-reporter-id 5a55a32c-43c3-44c3-afdc-72a219143f27| |Screen Reader|no| |VM|0%|
Extensions (40) Extension|Author (truncated)|Version ---|---|--- markdown-preview-github-styles|bie|1.0.1 gitignore|cod|0.7.0 vscode-markdownlint|Dav|0.46.0 vscode-eslint|dba|2.2.2 dendron|den|0.81.0 dendron-markdown-preview-enhanced|den|0.10.57 dendron-markdown-shortcuts|den|0.12.1 dendron-paste-image|den|1.1.0 dendron-snippet-maker|den|0.1.6 gitlens|eam|11.7.0 gauge|get|0.1.0 go|gol|0.31.1 rest-client|hum|0.24.6 jenkins-pipeline-linter-connector|jan|1.2.0 intellij-idea-keybindings|k--|1.5.0 code-groovy|mar|0.1.2 dotenv|mik|1.0.1 vscode-docker|ms-|1.19.0 python|ms-|2022.0.1814523869 vscode-pylance|ms-|2022.2.1 jupyter|ms-|2022.1.1001821375 jupyter-keymap|ms-|1.0.0 jupyter-renderers|ms-|1.0.6 remote-containers|ms-|0.217.2 vscode-ginkgo|ons|0.0.1 java|red|1.3.0 vscode-commons|red|0.0.6 vscode-yaml|red|1.4.0 ginkgo-lens|sel|1.0.0 rewrap|stk|1.16.1 code-spell-checker|str|2.1.6 vscodeintellicode|Vis|1.2.17 vscode-conventional-commits|viv|1.24.0 vscode-gradle|vsc|3.10.0 vscode-java-debug|vsc|0.38.0 vscode-java-dependency|vsc|0.19.0 vscode-java-pack|vsc|0.21.0 vscode-java-test|vsc|0.34.0 vscode-maven|vsc|0.35.0 vscode-open-in-github|ziy|1.3.6
lszomoru commented 2 years ago

Could you please share the contents of the Git output channel which you can access by invoking the Git: Show Git Output command in the command palette? Thanks!

egr95 commented 2 years ago

Having the exact same issue since I updated VSCode last week!

FWIW, here's my Git output channel [2022-02-14T21:19:16.256Z] Validating found git in: /usr/bin/git [2022-02-14T21:19:16.398Z] Using git 2.24.1 (Apple Git-126) from /usr/bin/git [2022-02-14T21:19:16.496Z] > git rev-parse --git-dir [53ms] [2022-02-14T21:19:16.498Z] Open repository: /Users/elliott/Documents/GitHub/ssCoDA [2022-02-14T21:19:16.590Z] > git symbolic-ref --short HEAD [31ms] [2022-02-14T21:19:16.673Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/master refs/remotes/master [15ms] [2022-02-14T21:19:16.736Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [56ms] [2022-02-14T21:19:16.775Z] > git remote --verbose [54ms] [2022-02-14T21:19:16.800Z] > git config --get commit.template [20ms] [2022-02-14T21:19:17.206Z] > git ls-files --stage -- /Users/elliott/Documents/GitHub/ssCoDA/code/train_and_evaluate.py [34ms] [2022-02-14T21:19:17.208Z] > git ls-files --stage -- /Users/elliott/Documents/GitHub/ssCoDA/code/utils.py [35ms] [2022-02-14T21:19:17.227Z] > git cat-file -s 0d340972158cd447e9b5a88f1c9bdea98a12dc87 [19ms]
vmatyus commented 2 years ago

Thanks to this problem I switched VS Code with another IDE tool (IntelliJ) and today I opened the VS code with the project and I cannot see the Electron peak anymore. I hope this will be permanent. I've check the Git: Show Git Output as per you requested:

Current Git Output ``` [2022-02-15T09:16:46.854Z] Validating found git in: /usr/bin/git [2022-02-15T09:16:47.173Z] Using git 2.32.0 (Apple Git-132) from /usr/bin/git [2022-02-15T09:16:47.276Z] > git rev-parse --git-dir [32ms] [2022-02-15T09:16:47.281Z] Open repository: {repo_path} [2022-02-15T09:16:47.582Z] > git ls-tree -l HEAD -- {path_to_file}common.py [247ms] [2022-02-15T09:16:47.651Z] > git symbolic-ref --short HEAD [75ms] [2022-02-15T09:16:47.711Z] > git ls-tree -l HEAD -- {path_to_file}common.py [73ms] [2022-02-15T09:16:47.725Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/{branch_name} refs/remotes/{branch_name} [69ms] [2022-02-15T09:16:47.767Z] > git remote --verbose [38ms] [2022-02-15T09:16:47.814Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [86ms] [2022-02-15T09:16:47.864Z] > git config --get commit.template [35ms] [2022-02-15T09:17:04.297Z] > git ls-tree -l HEAD -- {path_to_file}common.py [39ms] [2022-02-15T09:17:39.211Z] > git ls-tree -l HEAD -- {path_to_file}common.py [36ms] [2022-02-15T09:17:55.033Z] > git ls-tree -l HEAD -- {path_to_file}common.py [55ms] [2022-02-15T09:17:58.286Z] > git log --format=%H%n%aN%n%aE%n%at%n%ct%n%P%n%B -z -n21 -- {path_to_file}common.py [45ms] [2022-02-15T09:19:51.158Z] > git ls-tree -l HEAD -- {path_to_file}common.py [46ms] [2022-02-15T09:21:48.985Z] > git ls-tree -l HEAD -- {path_to_file}common.py [49ms] [2022-02-15T09:22:09.524Z] > git ls-tree -l HEAD -- {path_to_file}common.py [40ms] [2022-02-15T09:24:55.672Z] > git ls-tree -l HEAD -- {path_to_file}common.py [50ms] ```
imageslr commented 2 years ago

Having same issue after I updated VSCode.

In Activity app I can see that Code - Electron - java causing high cpu.

sidwebworks commented 2 years ago

Same issue on M1 macbook air, with vscode, the moment it loads up electron usage goes to 100%.

Initially i thought it could be because of electron and some bug with it, but I also heavily use discord, But only in the case of vscode the electron usage was 100%

sidwebworks commented 2 years ago
image

Can't do anything, TS intellisense also takes too long due to this

sidwebworks commented 2 years ago

@lszomoru I can think the issue is with Version: 1.64.2, I uninstalled it and installed the code-insiders edition to test. It worked fine for some time, until i opened a typescript file. the usage again went to 90%

image
lszomoru commented 2 years ago

@sidwebworks, that for the additional information. Does CPU usage increases as soon as you open the typescript file? Does the CPU usage maintains?

@mattbierner, would an extension host profile help track down the CPU consumption when opening a typescript file?

sidwebworks commented 2 years ago

Hi @lszomoru I managed to solve this issue, you can read more about it here. https://github.com/MicrosoftDocs/live-share/issues/4539#issuecomment-1051056537

lszomoru commented 2 years ago

Thanks @sidwebworks for the update. @mattbierner, could you please take a look as the issue could be related to TypeScript. Thanks!

mjbvz commented 2 years ago

@sidwebworks So you don't see this issue when using VS Code insiders with TS 4.4.x? What about when using TS 4.6?

If you still see this issue, can you share a project and specific steps to reproduce the issue so we can investigate?

sidwebworks commented 2 years ago

@mjbvz Yeah sure would love to help as much as I can, honestly there were 2 main issues I was facing due to the 100% CPU.

  1. Intellisense was too slow and soon whole vscode freezed.

  2. Trying to build any project with used TS was just hanging up and hogging on CPU.

Switching to vscode-insiders also didn't fix it for me. Not even a clean mac os installation fixed it.

At last the moment I switched to the nightly TS/JS extension and reloaded vscode, all the issues related to the editor freezing and Intellisense were gone.

But the builds still didn't work. Soon I saw an issue on TSC where there was some infinite recursion going on in the compiler. Which caused that issue. So downgrading the typescript version to 4.4.4 fixed it.

So far it's been fine but if anything breaks I'll report here with a repro.

I will try to repro the bug is possible, by switching back to the old extension. Will see if it breaks again.

mjbvz commented 2 years ago

Closing as it seems like @vmatyusGitHub can no longer reproduce this issue

High cpu usage is a very generic symptom with many possible causes so if you are still seeing perf problems, please open a new issue so we can investigate separately

sneila commented 2 years ago

After the APR 2022 update, high electron usage, my Intel Mac (which is a beast, see screenshot below) is constantly spinning the fans!! http://b3.ms/aKb9Lzj7Jn3R

gieljnssns commented 2 years ago

After apr update I'm seeing also high cpu on electron. Going back to march solves this...

vmatyus commented 2 years ago

Can you please share some steps what can I do, when I experiencing the high cpu load? (to help you in the investigation)

gieljnssns commented 2 years ago

Just starting vscode is enough to get the electron process to 100%

vmatyus commented 2 years ago

I mean @mjbvz would you please help us in providing some steps how can we help you in the investigation, can I provide some info about the Electron or where can I check Electron logs?

sneila commented 2 years ago

@vmatyusGitHub As stated above, just start VS CODE. For me it was like this: Vs Code has updates, cool, restart computer, restart apps. Restarted Mac, hoped for the app to be restarted and updated, did not happen, restarted the app to apply the update. Fans started working the soon i restarted vscode, verified if indexing is happening in the background, restarted multiple times vsCode, cpu usage is always 100%+, ~120% minimised, ~150% maximised/focused. There is no much i can tell you to reproduce, for me is standard usage.

Day by day:

jmca commented 2 years ago

Have you tried following the steps on https://github.com/microsoft/TypeScript/wiki/Performance-Tracing? This page helped me isolate my TS CPU/Electron process issues. If you want, you can upload the trace.json file so we (at least me) can take a look. My issue was due to an updated library and its complex type definitions that were killing the "type checking phase" of the trace.

sneila commented 2 years ago

@jmca yes, not going to happen (i do not have the time for this), downgraded to 1.66 for now, it works fine, until it gets figured it out, will stay on this release.

AlexanderProd commented 2 years ago

same here since updating to 1.67 using a M1 Pro MacBook Pro

vmatyus commented 2 years ago

Now, I've updated to Version: 1.67.0 , Electron: 17.4.1 I hope there will be no more problem with Electron there.

Have you tried following the steps on https://github.com/microsoft/TypeScript/wiki/Performance-Tracing?

No, but I will when I meet this problem again. Thanks!

vmatyus commented 2 years ago

I run this issue again. It took a few seconds to create tsconfig.json file with this load: Screen Shot 2022-05-11 at 17 54 38 The Git: Show Git Output command shows this constantly: Screen Shot 2022-05-11 at 17 58 01

I tried to run this tsc solution, but my project is not fuly a js/ts project, however has some a folder with js files, so I created tsconfig.json there in a folder. I created this snapshot, but could not catch the Electron with it. Here is a snapshot from the Activity Monitor: Screen Shot 2022-05-11 at 18 29 46

There was an old node_module directory in one of the folders, I deleted it, since it is not needed anymore. I hope this solved the issue... I need to change node version here-and-there, so the "type checking phase" in node could be also a problem in my case too.

mjbvz commented 2 years ago

@vmatyusGitHub If you are still seeing issues, follow these instructions to see which subprocess has high cpu usage https://github.com/microsoft/vscode/wiki/Performance-Issues#visual-studio-code-is-consuming-a-lot-of-cpu

Justintime50 commented 2 years ago

@mjbvz the link provided only details how to do this on Windows. Are there other docs describing it on macOS? I've searched for the Help>Open Process Explorer prompt per the guide and it doesn't appear on macOS.

mjbvz commented 2 years ago

@Justintime50

image

Or run it from the command palette

Justintime50 commented 2 years ago

@mjbvz thank you! For whatever reason, this isn't indexed in the search box under help but is appearing at either location.

pvelin commented 2 years ago

I tested with a simple NodeJS project. Opening vscode everything is ok. Opening simple JS file with a normal function and an export, everything is ok. Then opening a JS file which is loading a npm module (require('axios') ) and one of the Electron processes goes to 100% and fans start to spin up. Checking the process explorer it is tsserver.js. Reverting back to january release 1.64.2 and problem goes away. That is the last version working.

OS: MacOS 12.3.1

mjbvz commented 2 years ago

@pvelin Please open a new issue. Be sure to include a sample project so we can try to reproduce the problem

AlexanderProd commented 2 years ago

I have around 26% cpu usage with an open python file. And the fans on my 16" M1 Pro MBP turn up despite them being usually shut off.

VSCode: 1.67.1 OS: MacOS 12.3.1

sneila commented 2 years ago

@mjbvz Thank you for pointing it out, this way i found out that VUE/VOLAR plugin/extension was causing the overhead (200%+ CPU time o_O ). My Vscode is finally "silent" again. (ps: still need to work full day to know that it's fully silenced)

pvelin commented 2 years ago

Mine is silent too. I had a Javascript config object that I was exporting with module.exports = config and after that individually exporting exports.foo = config.foo, exports.bar = config.bar. This will put one of the Electron processes to 100%. Removing those individual exports and everything is ok. In my previous post I thought it was something to do with importing npm module but was not. It was old code. I cleaned up and now everything is fine.

mjbvz commented 2 years ago

If you are not @vmatyusGitHub, please stop posting in this thread and open new issues if you are still seeing problems

vmatyus commented 2 years ago

Turned out this Electron process also could block the results from global search. Next time I hope I can make some digging.

vmatyus commented 2 years ago

I met with this problem again and now I could filter down to 1 extension: Gauge I made the profile recording for 30s long.

Screen Shot 2022-05-20 at 11 56 34

  0    360   31235     window ( my-file — my-folder-have-multiple-gauge-projects)
   -->99<--    197   31305     extensionHost
    0       49   31563       /Library/Java/JavaVirtualMachines/ibm-semeru-open-8.jdk/Contents/Home/bin/java -jar ${USERFOLDER}/.vscode/extensions/vscjava.vscode-gradle-3.12.0/lib/gradle-language-server.jar
    0       49   31571       /Library/Java/JavaVirtualMachines/ibm-semeru-open-8.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -classpath ${USERFOLDER}/.vscode/extensions/vscjava.vscode-gradle-3.12.0/lib/gradle-server.jar com.github.badsyntax.gradle.GradleServer 58907
    0       16   31594       /Applications/Visual Studio Code.app/Contents/MacOS/Electron --ms-enable-electron-run-as-node ${USERFOLDER}/.vscode/extensions/streetsidesoftware.code-spell-checker-2.2.0/packages/_server/dist/main.js --node-ipc --clientProcessId=31305
    0       33   31915       /Applications/Visual Studio Code.app/Contents/MacOS/Electron --ms-enable-electron-run-as-node ${USERFOLDER}/.vscode/extensions/ms-python.vscode-pylance-2022.5.2/dist/server.bundle.js --cancellationReceive=file:9843c48d76668a04f4b96cab6ac5469a4d05a5fbd0 --node-ipc --clientProcessId=31305

I have a fodler with multiple gauge project, this might cause trouble for the VSCode. I set the Gauge extension to disabled, but still causes the same CPU result.

wetenhall commented 2 years ago

Updated to the latest version and have now gone back to November 2021 (version 1.63). please solve this issue as the updates in the new version were quite nice...

hishark commented 2 years ago

Updated to the latest version and have now gone back to November 2021 (version 1.63). please solve this issue as the updates in the new version were quite nice...

downgrade from 1.67 to 1.63 finally solved my problem 😭😭😭

percy507 commented 2 years ago

Same question on upgrading 1.67.

After checking Process Explorer, I find it was the extension host consume high CPU.

Refer the issue, run Help: Start Extension Bisect command, I find if I disable Settings Sync extension, the CPU will be normal in my case. Weird!!!🤯

leondeng commented 2 years ago

Thanks guys, for me, it was the extension CSS Peek, after uninstalled it, all good now.

Yue-Zhengyuan commented 2 years ago

For me it is the Pylance extension (v.2022.5.3).

pebell commented 2 years ago

Settings Sync was the culprit for me. But with the variety of extensions mentioned here, it seems safe to assume the extensions themselves may cause the symptoms, but are not the root cause of the problem.

NikoHelle commented 2 years ago

I also disabled Settings Sync and the problem was resolved. Before that every open VSCode window had an Electron process constantly using 40-70% CPU.