microsoft / vscode

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

High CPU usage from node.mojom.NodeService #213136

Open petoknm opened 1 month ago

petoknm commented 1 month ago

Type: Performance Issue

This specific process always takes 100% CPU on machine:

/snap/code/159/usr/share/code/code --type=utility --utility-sub-type=node.mojom.NodeService --lang=en-US --service-sandbox-type=none --no-sandbox --crashpad-handler-pid=860961 --enable-crash-reporter=f5630c5d-bec1-43e9-95d6-21d878227126,no_channel --user-data-dir=/home/pmajchrak/.config/Code --standard-schemes=vscode-webview,vscode-file --secure-schemes=vscode-webview,vscode-file --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --code-cache-schemes=vscode-webview,vscode-file --shared-files=v8_context_snapshot_data:100 --field-trial-handle=0,i,4729389318826606528,17009332704461783735,262144 --enable-features=kWebSQLAccess --disable-features=CalculateNativeWinOcclusion,SpareRendererForSitePerProcess --variations-seed-version

I looked at the different ways to profile VSCode, but they didn't show this process, so it all looked normal. Even JS profiling doesn't capture this. This process still exists even if I run VSCode with disabled extensions and the process respawns after being killed.

VS Code version: Code 1.89.1 (dc96b837cf6bb4af9cd736aa3af08cf8279f7685, 2024-05-07T05:16:23.416Z) OS version: Linux x64 5.15.0-105-generic snap Modes:

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 9 5950X 16-Core Processor (32 x 4464)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|2, 2, 2| |Memory (System)|62.70GB (52.78GB free)| |Process Argv|--no-sandbox --force-user-env --crash-reporter-id 18e3b18c-bfb2-4aff-9683-a7fc868c85da| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|ubuntu| |XDG_CURRENT_DESKTOP|Unity| |XDG_SESSION_DESKTOP|ubuntu| |XDG_SESSION_TYPE|x11|
Process Info ``` CPU % Mem MB PID Process 0 128 860943 code main 0 0 860945 zygote 0 0 860946 zygote 0 193 860993 window [1] (test - Visual Studio Code) 0 321 876526 window 0 0 876605 utility-process 0 64 876682 window [3] (Issue Reporter) 0 257 860973 gpu-process 0 64 860980 utility-network-service 0 64 861272 shared-process 0 0 876715 /usr/bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command= 0 64 861323 ptyHost 3 2183 874163 fileWatcher [1] 0 64 874175 extensionHost [1] ```
Workspace Info ``` | Window (test - Visual Studio Code) | Folder (test): more than 24175 files | File types: siginfo(4707) ipk(2493) zst(2272) pyc(1408) py(1405) | pyi(557) json(382) so(226) html(118) test(71) | Conf files: makefile(3) settings.json(2) dockerfile(2); ```

Extensions: none

A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
tftest:31042121
vswsl492cf:30256860
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pythonmypyd1:30879173
pythoncet0:30885854
h48ei257:31000450
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
chatpanelc:31048052
dsvsc021:30996838
f3je6385:31013174
pythoncenvpt:31049070
a69g1124:31046351
pythonprt:31047983
dwnewjupytercf:31046870
fa862199:31048878

tomaszkapron commented 1 month ago

Having similar issues

javierjcf commented 1 month ago

Same here

edithli commented 1 month ago

similar issues here on Mac

/private/var/folders/rd/pts24m5j6x35m7ytf_q60yn80000gn/T/AppTranslocation/A5742310-7FCA-4A76-9CE4-CA349B49206B/d/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --type=utility --utility-sub-type=node.mojom.NodeService --lang=en-US --service-sandbox-type=none --dns-result-order=ipv4first --inspect-port=0 --user-data-dir=/Users/lss/Library/Application Support/Code --standard-schemes=vscode-webview,vscode-file --enable-sandbox --secure-schemes=vscode-webview,vscode-file --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --code-cache-schemes=vscode-webview,vscode-file --shared-files --field-trial-handle=1718379636,r,11998688379030772291,12062321241314744751,262144 --enable-features=kWebSQLAccess --disable-features=CalculateNativeWinOcclusion,SpareRendererForSitePerProcess --variations-seed-version

vs code version:

Version: 1.88.0 (Universal)
Commit: 5c3e652f63e798a5ac2f31ffd0d863669328dc4c
Date: 2024-04-03T13:28:18.899Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin arm64 23.4.0

system info

macOS Sonoma Version 14.4.1 (23E224)

image

image

deepak1556 commented 1 month ago

That would be the extension host process, disable extensions will only have effect on installed extensions, builtin ones will be run and seems like an issue from one of them. Please use the following steps to capture a cpu profile of the process,

* Launch vscode like `code --inspect-extensions=9229`
* In chrome browser visit chrome://inspect/ or in edge browser visit edge://inspect
* You should see an entry under Remote Target
* If you don't see the above entry, then
  * Under Devices, click open dedicated devtools for node
  * Under Connection tab, add localhost:9229
  * You should now see the target
  * If there are multiple targets pick the one that matches the PID of the process showing high cpu
* Click inspect
* Go to Profiler tab and start the CPU profiler
* Stop the profiler after a few seconds and attach it to this issue.
jvinolas commented 1 month ago

Bug also reproduced. It happens to me a the paste from clipboard action, sometimes.

Version: 1.89.1 Commit: dc96b837cf6bb4af9cd736aa3af08cf8279f7685 Date: 2024-05-07T05:16:23.416Z Electron: 28.2.8 ElectronBuildId: 27744544 Chromium: 120.0.6099.291 Node.js: 18.18.2 V8: 12.0.267.19-electron.0 OS: Linux x64 6.8.0-31-generic

xrstf commented 1 month ago

Same here.

Version: 1.89.1 Commit: dc96b837cf6bb4af9cd736aa3af08cf8279f7685 Date: 2024-05-07T05:16:23.416Z Electron: 28.2.8 ElectronBuildId: 27744544 Chromium: 120.0.6099.291 Node.js: 18.18.2 V8: 12.0.267.19-electron.0 OS: Linux x64 6.1.0-21-amd64

petoknm commented 1 month ago

The issue stopped happening on my machine, at least for now, so I can't perform the extra profiling at the moment. However, I would really appreciate if people who do experience this issue, performed the profiling according to comment https://github.com/microsoft/vscode/issues/213136#issuecomment-2141179362 instead of just commenting that it happens. We need to give the team more data to debug this issue. Thank you.

xrstf commented 1 month ago

Updating to 1.90.1 did not solve the issue. The moment I have a workspace open, the file watcher process continues to use 100% of one CPU core.

Geczy commented 1 month ago

have the same issue, did not see anything in vscode process explorer showing an extension that was using high cpu. it just said extension host was high

mgates 94478 138.3 0.1 1594142160 52704 ?? R 5Jun24 8461:12.92 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --type=utility --utility-sub-type=node.mojom.NodeService --lang=en-US --service-sandbox-type=none --dns-result-order=ipv4first --inspect-port=0 --user-data-dir=/Users/mgates/Library/Application Support/Code --standard-schemes=vscode-webview,vscode-file --enable-sandbox --secure-schemes=vscode-webview,vscode-file --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --code-cache-schemes=vscode-webview,vscode-file --shared-files --field-trial-handle=1718379636,r,7905944025835438358,16796389049385230011,262144 --enable-features=kWebSQLAccess --disable-features=CalculateNativeWinOcclusion,SpareRendererForSitePerProcess --variations-seed-version

petoknm commented 1 month ago

Please profile according to https://github.com/microsoft/vscode/issues/213136#issuecomment-2141179362

Geczy commented 3 weeks ago

@petoknm there is no profiler, but there is a "performance" tab that i can record with. let me know if i did it right. i can try again

200%+ cpu usage @deepak1556

CPU-20240618T061059.cpuprofile

another CPU-20240618T061552.cpuprofile

saw an extension be mentioned in that last one, so i uninstalled live share and live preview extensions here's two new profiles, each a few seconds long CPU-20240618T062133.cpuprofile CPU-20240618T062130.cpuprofile

petoknm commented 3 weeks ago

Thank you @Geczy . I can confirm I am able to open the cpuprofile and see the recording.

I see a lot of callbackTrampoline calls, which suggests async work. Some of the higher CPU usage sections have a lot of readdir calls.

So to me it looks like VSCode is scanning (probably) the project files and therefore this issue could be caused by opening large projects? The project that was causing issues for was indeed quite large (multiple git submodules)

Geczy commented 3 weeks ago

looking at bottom-up i saw more referencing kevinmcgowan.TypeScriptImport so i uninstalled this extension as well. seems like this was the culprit, because I no longer see high CPU usage. the bottom up calls were garbage collecting and globbing and readdir, lke you said

https://marketplace.visualstudio.com/items?itemName=kevinmcgowan.TypeScriptImport

they even have a high cpu issue: https://github.com/microsoft/vscode/issues/213136#issuecomment-2175966016

and this extension hasn't been touched in 7 years

i'm going to consider this solved for me ! thanks for the inspection help

will come back if i notice usage is super high again

fuunnx commented 3 weeks ago

Same story here, but different extension. vscode-gitblame is the culprit.

There is a lot of calls to async_hooks that causes a lot of computation (with registerDestroyHook). I guess those extensions were developed in a time before async_hooks were introduced. But now, async_hooks add a lot of overhead.

Here is the CPU profile for the curious :

mojom-CPU-20240620T100137.cpuprofile

3ng7n33r commented 3 weeks ago

Same problem here since my last VSCode update to version 1.90.2.

The culprit seems to be the dev-container extension for me. In addition to the CPU load, it also blocks a port that my application needs to function. Killing the process unblocks the port and makes everything run smooth again until I restart the dev-container. After I kill it, VSCode presents me with an error message: A shared background process terminated unexpectedly. Please restart the application to recover. which can be ignored for now as vscode and the container seem to work completely fine.

ravm commented 2 weeks ago

Same issue here, except the CPU usage will stay at 100% unless I disable all extensions including VSCode's built-in extensions.

javierjcf commented 2 weeks ago

I uninstall gitlens extension. I have long projects with a lot of git repositories inside. gitlens eatc my cpu and ram