7

I have been learning python using VScode. I've noticed recently that as soon as I start VScode my CPUs get maxed out and my whole computer is sluggish. When I run the activity monitor I see as many as 5 rg processes running and up to 4 'Code Helper' processes. These processes use up to 125% of CPUs. When I quit VScode, the Activity Monitor still reports a lot of cpu percentage for 'Code Helper', and continues reporting that for over 20 minutes after I quit VScode. Does anyone have any idea why VScode is using so much cpu time? I'm using the latest VScode on my iMac running High Sierra 10.13.5 and VScode version 1.24.1

2 Answers 2

6

High CPU is caused most probably by some VS Code extensions. Try running VS Code with all extensions disabled and check if You still experience such CPU. From my experience the Import Cost extension can cause quite high CPU load..

If the CPU is allright with extensions disabled try enabling it one-by-one (work a little bit between enabling every next one) and try to locate which extension is a real CPU eater.

Here is a very good article about troubleshooting performance issues with VS Code: https://github.com/Microsoft/vscode/wiki/Performance-Issues

Good luck!

2

For those happy in the terminal, there might be a shortcut to experimenting to see which extension is at fault

Just had to solve it so thought I'd share what I found (yes, this approach ought to work on Linux as well)..

First, my top command had this to say. Note that PID - 22032 - and that Code Helper is the guilty party (note: the issue was fixed before I posted this so I can't re-run top and get its output as text).

enter image description here

However... Code Helper provides shared services around many extensions so that doesn't tell you which one is bad.

Next, step, what's at 22032?

Well, I figured it was searchable by pgrep so I ran this:

(note that there is specifically an .vscode/extensions/xxx argument to this Code Helper).

pgrep -lafi 'Visual Studio Code.app'

... other VS Code PIDs ...

👉22032👈 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node 
👉/Users/me/.vscode/extensions/ms-python.vscode-❌pylance❌-❌2022.10.30/dist/server.bundle.js 👈--cancellationReceive=file:6fcd56f299db327bd6a77767eb05e4f2ba27254a98 --node-ipc --clientProcessId=19541

... other VS Code PIDs ...

For some reason pylance had been acting up and wouldn't quit even when VSCode was down. I don't think there was anything particularly wrong with Pylance right now, I think it just got itself caught in an infinite loop somehow.

But if this happens again, I will investigate specifically Pylance.

This killed it btw:

pkill -lafi 'Visual Studio Code.app'

p.s. In fact the 100% CPU has been recurring. So I went to the Extensions page, found Pylance, clicked the ⚙️ (gear) icon and selected Install another version... and picked one from 2 weeks ago. Nice! (though I'd prefer to have the latest working).

4
  • Please show text as text not as an image which is difficult to read.
    – mmmmmm
    Oct 28, 2022 at 17:52
  • can't. the top screenshot was taken before I fixed the problem. However I did copy the output of pgrep at the time, to search for it in a text file. After I fixed my problem I thought of looking here to see if this had been asked before.
    – JL Peyret
    Oct 28, 2022 at 18:06
  • Visual Studio Code has a very helpful Process Explorer which provides the same info and lets you copy stuff.
    – maryisdead
    Apr 24 at 15:23
  • @maryisdead great point. You could probably write an answer based on that. Not that the accepted answer is badly wrong, but … it’s a bit on the ”Have you tried turning it off and on again?” end of things.
    – JL Peyret
    Apr 24 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .