Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High CPU usage spikes when doing virtually anything in JS/TS files (M2 Mac) #173989

Closed
viggobf opened this issue Feb 9, 2023 · 20 comments
Closed
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@viggobf
Copy link

viggobf commented Feb 9, 2023

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

  • VS Code Version: 1.75.0
  • OS Version: macOS 13.2

Steps to Reproduce:

  1. Type code in VSCode (with ReactJS and JSX)

Hi, this probably seems really basic but I've been having an issue with VSCode 1.75.0 on my M2 MacBook Air running the Apple silicon build on macOS 13.2. I work with React, and do not use the built-in terminal. Settings Sync is thankfully off.

Essentially, everything I do in the editor, things as basic as simply typing a character or commenting/uncommenting a line, cause CPU usage to spike and temperatures to rise. The consequence of this is that VSCode is always on the Using Significant Energy list, and my battery level drops much faster when editing code.

I have disabled all extensions (therefore running the app effectively vanilla, uninstalled and reinstalled VSCode, tried older versions, same issue. This is really annoying and significantly deteriorates battery life so help appreciated.

@vscodenpa
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.75.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@tarasis
Copy link

tarasis commented Feb 9, 2023

I had no issue with 1.75.0 but after upgrading to 1.75.1 VSCode is idling at 35-50% CPU usage on an M1 MacBook Air, even off screen in a different desktop without any interaction and all tabs closed.

According to "Process Explorer" in VSCode its the Shared Process that it taking up that CPU Usage

shared-process 39% 164MB 73794 PID

Output from "Copy All" on that process

Process Name
CPU (%)
Memory (MB)
PID
code main
1
164
73703
gpu-process
0
66
73709
utility-network-service
0
33
73711
window (eleventy-plugin-syntaxhighlight-chroma)
0
262
73712
extension-host
0
344
73792
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/markdown-language-features/server/dist/node/main --node-ipc --clientProcessId=73792
0
49
73881
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/tarasis/.vscode/extensions/hex-ci.stylelint-plus-0.56.6/server.js --stdio --clientProcessId=73792
0
66
73882
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/tarasis/.vscode/extensions/formulahendry.auto-rename-tag-0.1.10/packages/server/dist/serverMain.js --node-ipc --clientProcessId=73792
0
33
73883
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/tarasis/.vscode/extensions/ms-edgedevtools.vscode-edge-devtools-2.1.1/node_modules/vscode-webhint/dist/src/server.js /Users/tarasis/Library/Application Support/Code/User/globalStorage/ms-edgedevtools.vscode-edge-devtools Microsoft Edge Tools --node-ipc --clientProcessId=73792
0
115
73892
/opt/homebrew/bin/deno lsp
0
49
73895
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=73792
0
33
73898
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/tarasis/.vscode/extensions/dbaeumer.vscode-eslint-2.4.0/server/out/eslintServer.js --node-ipc --clientProcessId=73792
0
49
73916
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/tarasis/.vscode/extensions/streetsidesoftware.code-spell-checker-2.16.0/packages/_server/dist/main.js --node-ipc --clientProcessId=73792
0
82
73917
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/tarasis/.vscode/extensions/vunguyentuan.vscode-css-variables-2.6.3/dist/server.js --node-ipc --clientProcessId=73792
0
49
73918
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node --max-old-space-size=3072 /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --serverMode partialSemantic --useInferredProjectPerProjectRoot --disableAutomaticTypingAcquisition --cancellationPipeName /var/folders/6l/gz5hk_fn19714ftsd5fhypfm0000gn/T/vscode-typescript501/9daeb97bbf568a88d38a/tscancellation-3f27893e9d4094eea91b.tmp* --globalPlugins typescript-deno-plugin --pluginProbeLocations /Users/tarasis/.vscode/extensions/denoland.vscode-deno-3.17.0 --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc
0
98
74217
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node --max-old-space-size=3072 /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName /var/folders/6l/gz5hk_fn19714ftsd5fhypfm0000gn/T/vscode-typescript501/9daeb97bbf568a88d38a/tscancellation-20e7de80cec7ab4dd77f.tmp* --globalPlugins typescript-deno-plugin --pluginProbeLocations /Users/tarasis/.vscode/extensions/denoland.vscode-deno-3.17.0 --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc
0
164
74218
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typingsInstaller.js --globalTypingsCacheLocation /Users/tarasis/Library/Caches/typescript/4.9 --enableTelemetry --typesMapLocation /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typesMap.json --validateDefaultNpmLocation
0
66
74223
/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/tarasis/.vscode/extensions/pranaygp.vscode-css-peek-4.2.0/server/out/server.js --node-ipc --clientProcessId=73792
0
49
74232
shared-process
39
164
73794
ptyHost
0
49
73795
fileWatcher
0
49
73909
process-explorer
0
131
74422
/bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
0
0
74744

Screenshot 2023-02-09 at 21 07 09

I only noticed when I saw that the CPU was at 46-47 degrees.

@mjbvz
Copy link
Collaborator

mjbvz commented Feb 9, 2023

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

@tarasis Can you please open a different issue for your problem

@mjbvz mjbvz added the info-needed Issue requires more information from poster label Feb 9, 2023
@viggobf
Copy link
Author

viggobf commented Feb 10, 2023

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

@tarasis Can you please open a different issue for your problem

Yes it does, same issue.

@viggobf
Copy link
Author

viggobf commented Feb 26, 2023

@mjbvz any ideas on why this could be happening?

@tarasis
Copy link

tarasis commented Feb 26, 2023 via email

@viggobf
Copy link
Author

viggobf commented Feb 26, 2023

Yeah same here, small very lightweight files like md or txt files do not bring out the issue but my large JS/JSX files have the issue; simply typing one character sends CPU temps from 30-38C to over 50C. However when idle/in a different desktop the issue does not occur, only when actively editing.

@tamuratak
Copy link
Contributor

@Viggo2

Minimap might be the cause. Disable Minimap. See #169775 (comment)

Related to #148226

@viggobf
Copy link
Author

viggobf commented Feb 27, 2023

@Viggo2

Minimap might be the cause. Disable Minimap. See #169775 (comment)

Related to #148226

Doesn't appear to make much difference I'm afraid

@viggobf
Copy link
Author

viggobf commented Feb 27, 2023

@tamuratak I've been experimenting with different file types and it seems that the issue seems to be isolated to JavaScript files (mine tend to be quite large and include JSX). When editing in other files, of similar sizes, in my React/Next site, CPU temperatures and usage remain stable. Even when starting completely blank, new JS files, the CPU usage rises and fluctuates a lot more than when editing in, eg, massive CSS files.

Fyi extensions attached below, but to me these don't largely seem applicable to this issue.
image

@viggobf viggobf changed the title High CPU usage spikes when doing virtually anything (M2 Mac) High CPU usage spikes when doing virtually anything in JS/TS files (M2 Mac) Feb 27, 2023
@viggobf
Copy link
Author

viggobf commented Mar 1, 2023

@tamuratak @mjbvz Have been further experimenting and it appears the JS/TS Language Features built-in extension is the culprit - disabling it stops the CPU spikes. However, I'd like to have it enabled so are there any settings you know of within it that could improve performance if disabled/enabled? (so far I've tried setting typescript.disableAutomaticTypeAcquisition to true, no luck unfortunately).

@ianbunag
Copy link

ianbunag commented Mar 3, 2023

Same above. I have followed this guide to identify the culprit https://apple.stackexchange.com/questions/351761/vs-code-code-helper-process-using-more-than-100-cpu-on-macos.

Every time I trace something, force stop some process from the activity monitor and the CPU usage goes down, I disable the extension. However this doesn't seem to be tied to the extensions themselves as it keeps happening.

Extensions I have disabled so far:

What is common among those processes is they are using the TS language server:

ps aux | grep 13314
user         13314  88.5  3.9 447380960 652064   ??  R    10:35AM  16:14.17 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node --max-old-space-size=3072 /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName /var/folders/y0/x5lk6gms0k3115_pbkvw59n40000gn/T/vscode-typescript501/8cdb3bda8879f1f0889b/tscancellation-fbeb639ede07d133c5f3.tmp* --globalPlugins typescript-styled-plugin --pluginProbeLocations /Users/user/.vscode/extensions/jpoissonnier.vscode-styled-components-1.7.0 --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc
user         31118   0.0  0.0 407973536    960 s000  R+    1:25PM   0:00.00 grep 13314

ps aux | grep 13313
user         13313  43.3  1.8 447308560 297696   ??  S    10:35AM   4:03.42 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node --max-old-space-size=3072 /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --serverMode partialSemantic --useInferredProjectPerProjectRoot --disableAutomaticTypingAcquisition --cancellationPipeName /var/folders/y0/x5lk6gms0k3115_pbkvw59n40000gn/T/vscode-typescript501/8cdb3bda8879f1f0889b/tscancellation-a39097a2837e5934d2e6.tmp* --globalPlugins typescript-styled-plugin --pluginProbeLocations /Users/user/.vscode/extensions/jpoissonnier.vscode-styled-components-1.7.0 --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc
user         31218   0.0  0.0 407962688     48 s000  S+    1:25PM   0:00.00 grep 13313

Attached is a recording of the language server infinitely restarting from the status bar:
https://user-images.githubusercontent.com/42926334/222640833-e9b68836-878a-4ba8-b469-11dc1a92c790.mp4

I am using an M1 mac and have been experiencing this for more than a year.

@viggobf
Copy link
Author

viggobf commented Mar 5, 2023

image

Just used the same guide as @ianbunag to identify the extension causing issues through the good old command line, appears to be the built-in TS server typescript/lib/tsserver.js that is causing the high CPU usage.

@fenvalle
Copy link

fenvalle commented Mar 5, 2023

To investigate: Git commands (like checking diff) are causing ts server to rebuild files, maybe there is a chance of this being related to the cause of this issue
Could someone check if ts server with cpu usage without git still have spikes in cpu usage?
microsoft/TypeScript#52876

@viggobf
Copy link
Author

viggobf commented Mar 6, 2023

To investigate: Git commands (like checking diff) are causing ts server to rebuild files, maybe there is a chance of this being related to the cause of this issue
Could someone check if ts server with cpu usage without git still have spikes in cpu usage?
microsoft/TypeScript#52876

Thanks for your comment @fenvalle - as a matter of fact, I just tried copying and pasting some non-dependent sections of my main problematic JS file into an empty new file in an empty workspace (no dir opened, or Git). Then I tried making simple edits (the likes of which would cause big CPU usage spikes in the actual file), and I did not note any major CPU usage (worked as you'd expect).

Therefore, this could be related to Git potentially. Defo will further investigate.

Edit (one of many): on further investigation, just tried another project of mine that is a Node module but has no Git repo. No difference, so maybe it isn't Git causing the issue. Perhaps it is due to the sheer amount of IntelliSense it wants to process, any ideas on how to improve the performance of this?

@viggobf
Copy link
Author

viggobf commented Mar 10, 2023

@fenvalle @mjbvz @tamuratak: I've worked out the exact culprit for this, it is this setting for JavaScript (validation). Disabling it stopped the CPU spikes almost completely; now they are down to a much more expected level. While it isn't crucial to JS editing, this feature is nice to have on, so any ideas on why it could be causing these CPU spikes and potentially how to make it faster? Sorry to keep bothering you guys but this is something that is really bugging me - thank you so much for your assistance.
image

@Sjoerd82
Copy link

Same issue here, since not too long ago I get annoying spikes (annoying because my PC fan goes high/low all the time). But I cannot find this "Javascript > Validate" setting. Where can we disable this exactly?

@viggobf
Copy link
Author

viggobf commented Mar 12, 2023

@Sjoerd82 search for javascript: validate in Settings. Alternatively you can add "javascript.validate.enable": false in settings.json

@fenvalle
Copy link

@

@fenvalle @mjbvz @tamuratak: I've worked out the exact culprit for this, it is this setting for JavaScript (validation). Disabling it stopped the CPU spikes almost completely; now they are down to a much more expected level. While it isn't crucial to JS editing, this feature is nice to have on, so any ideas on why it could be causing these CPU spikes and potentially how to make it faster? Sorry to keep bothering you guys but this is something that is really bugging me - thank you so much for your assistance.
image

@deepak1556

@vscodenpa
Copy link

Hey @mjbvz, this issue might need further attention.

@Viggo2, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@viggobf viggobf closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

8 participants