Closed tapz closed 3 years ago
(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:
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).
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.
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=
Is there any workaround for this? I'm getting tired of listening the fan of my MacBook.
cc @deepak1556 @bpasero
@tapz Can you share the project that causes this?
@mjbvz Not the source code. But package.json yes.
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!):
{
"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"
}
}
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%.
@tapz Do you see this if you just use that package.json in a new project with a single js file?
@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:
Hey guys, I have the same problem on macOS Catalina after upgrading to 1.52.0.
Process:
OS:
VS Code:
1.52.0
940b5f4bb5fa47866a54529ed759d95d09ee80be
x64
Switch back to older Version 1.51 does not help! 👎
@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.
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.
Just tried to use the profiler. But nothing pops-up in the Profiler tab:
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.
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/
i got ~180% cpu in my python workspace
I have the same problem, Code helper (render) process > 230% CPU in a single python file.
macOS big sur Macbook Pro 16"
@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
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)
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)
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=
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?
@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.
@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!
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 ?
@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.
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.
@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?
@alexdima Don't we already support extension host profiling via the Running Extensions view? Like F1 > Show Running Extensions > Start Extension Host Profile
@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.
oh, now I understand. Thanks for clarifyiing
@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!
my vscode-html-css extension is now 1.2.0, and the cpu problem has gone
I added node_modules to Commonly Used - Files: Exclude and now the CPU usage is back to normal (6 to 10% of one core).
Likely file watching then. fyi @bpasero
No, nothing in https://github.com/microsoft/vscode/issues/112393#issue-765353545 hints to watcherService
, but possibly TypeScript runs their own watcher?
@tapz Do you see this problem if you use just the package.json you shared in a new project with a single js file?
Steps to Reproduce:
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:
After the first 10 minutes: