Visual Studio Code using large amounts of CPU
Asked Answered
F

14

18

I'm running Windows 10. VSCode, even when idle, takes up a consistent 26-30% of my cpu. I tried code --disable-extensions in CMD to check if an extension was causing the problem, but my performance was the same as with extensions.

When I used sublime text, I had a similar issue with the editor using large amounts of cpu on idle - the problem was with indexing, which could be turned off with a single line of code in the settings. I tried looking up indexing on VSCode, but I couldn't find anything pertaining to my issue. What could be the problem?

Farrish answered 16/8, 2018 at 22:17 Comment(1)
are you developing a typescript project?Shipwreck
R
38

For me the solution was disable extension auto updates and some extra settings for the search engine. The most efficient one was search.followSymlinks": false. I share my settings.json file.

"files.exclude": {
        "**/tmp/**": true,
        "**/node_modules/**": true,
        "**/.git/objects/**": true,
},
"files.watcherExclude": {
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true,
        "**/node_modules/**": true,
        "**/tmp/**": true,
        "**/dist/**": true
},
"search.exclude": {
        "**/node_modules/**": true,
        "**/dist/**": true,
        "**/tmp/**": true,
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true
},
"extensions.autoCheckUpdates": false,
"extensions.autoUpdate": false,
"search.followSymlinks": false
Rind answered 27/11, 2019 at 17:44 Comment(4)
It was super helpful!! Thanks.Bandwidth
Thanks dear, but this solution not worked for me.Hardy
This did nothing for meHendecasyllable
Fantastic! I did reinstall my mac completely with a new fresh Sonoma os, installed vscode and started to edit an .md -file. Directly, the cpu went crazy and this worked for me! A side note - one can also go Code -> Preferences -> Settings and search for "Follow Symlinks" and turn it off that way.Harner
E
8

VS code uses the file watcher to identify any changes in the files. You can exclude the folders containing multiple files and not require to watch continuously.

"files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/node_modules/**": true
}
Epitomize answered 30/9, 2019 at 7:33 Comment(0)
C
2

For me what solved the problem was turning off Auto Import extension, was working on a huge project, and only once I opened that project the VS Code started eating up my CPU, in the left bottom corner it said Scanning... I right clicked on it, and "manage extensions" appeared I clicked on it and immediately went to Auto Import extension, I turned it off and everything was back to normal. So point being try checking bottom left corner for some processes and try disabling those process and hopefully it works, or for at least some of you.

[EDIT] What you could also do is open Task Manager and you would see something like \> Visual Studio Code (8) I would click on the arrow to see the list of all VS Code processes and kill only those (in my case only one) that was/were making all the problems

Chancelor answered 11/1, 2019 at 8:41 Comment(1)
Similar for me. IntelliSense for CSS class names in HTML extension was looking for css classesSaccharose
W
2

The CPU went 100% for Electron each time I opened xml files. When I open more than one project, I get several CPU 100% Electron processes that freeze my mac.

This configuration solved it for me

settings.json

"files.exclude": {
    "*.xml": true
}

Source for the idea came from: https://vscode-docs.readthedocs.io/en/latest/supporting/faq/

The CPU for Electron is 0.1% now :)

Hope it will help someone with the same issue.

Washy answered 19/5, 2022 at 13:7 Comment(0)
G
1

Note: my goal was to know what consumes 100% CPU (extensions or vscode server).

  1. Uninstall/Disable all extensions.
  2. Restart VS Code server on the remote Linux server. you can press CTRL + SHIFT + P in VS Code and type or select "Remote-SSH: kill VS Code Server on Host…". Then select the hostname and try connecting again to the host.
  3. If the CPU is still at 100%, check htop and see which vs code server process is doing that. In my case it was the 'pylance' extension. Use kill PID to stop it. Your CPU levels should drop drastically now.
  4. Reinstall what extensions you need.

Extra note: if you are opening the workspace on the root path '/' like I do the CPU reaching 100% is a normal thing because of vs code file watcher, you will see a warning popup from vs code about this anyway.

Gathard answered 8/4, 2023 at 22:20 Comment(0)
C
1

In my case it was the shared-process that was using all of the available CPU. I removed all extensions, turned off sync and automatic upgrades, opened a single file in a clean directory. Nothing helped. VS Code was completely unusable. It just started doing this recently. I am at the latest SW version of VS Code (1.87.2). I used taskkill to kill the shared-process. The CPU recovered to normal and I haven't seen any problems in VS Code. Mind you, I only use VS Code as a file editor so maybe haven't noticed the impact of killing the shared-process.

Chymotrypsin answered 26/3, 2024 at 21:5 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Gowen
P
0

My Visual Studio Code CPU usage is high during startup, but decreases in under a minute. The computer is unusable during that minute - mouse and keyboard do not respond and the fans are full on.

Microsoft Live Share extension seems to be the culprit in my case. I am on Windows 10 using the Live share extension on a moderately sized repository.

Steps to reproduce:

  1. Open the repository folder in VSCode
  2. Install Live Share extension
  3. Close VSCode
  4. Reopen VSCode
  5. Observe 100% CPU and unusable mouse/keyboard for about 10 to 60 seconds
  6. Disable extension
  7. Close VSCode
  8. Reopen VSCode
  9. Observe no unusually high CPU

Hope this helps someone avoid the same frustration.

Patronymic answered 11/1, 2021 at 13:58 Comment(0)
E
0

Additionnaly to visual studio internal configuration you can fiddle with you Os's configs for it.

Beware to not clutter your scheduler, you must know what you're doing before "trying out".

On linux, you can adjust the NICE value for each process for instance. The equivalent on windows is described in the following article : https://www.itechtics.com/limit-cpu-usage/. Make some research if you aren't confident.

Exciter answered 1/7, 2021 at 14:36 Comment(0)
M
0

I had the same case. I deleted tons of no needed extensions. And now VS code doesn't use so much CPU.

Monegasque answered 2/9, 2022 at 4:8 Comment(0)
T
0

This is not a solution but a workaround:

If for any reason vscode continues using high cpu in linux, use cgroups feature of linux to control amount of cpu usage:

1- apt-get install cgroup-tools

2- create /etc/cgconfig.conf and add these lines:

group lowcpu {
   cpu {
      cpu.shares=100;
   }
}

3- create /etc/cgrules.conf and add these lines:

*:vscode cpu lowcpu
*:code cpu lowcpu

4-run two commands:

cgconfigparser -l /etc/cgconfig.conf
cgrulesengd

reference: https://gist.github.com/avoidik/1c7c53f02461f716aabebf3372a6199d

Tiloine answered 23/3, 2023 at 13:39 Comment(1)
what is the effect of this change? can it be customized? any downsides?Jackjackadandy
C
0

The simplest solution to this problem is to load a smaller Workspace. I.e. if you open up the c:\ or /home directory, VS-Code will try to index all of the files. Instead only open up the directory of your project, i.e. c:\work\python\project1 .

No need to uninstall plugins.

Cajeput answered 15/4, 2023 at 20:0 Comment(0)
S
0

SysInternals-->Procmon64.exe to the rescue!

The culprit for me was that is was sitting in a location which was actually a network share. Once installing node-modules, there was background tracking of files which was making numerous TCP requests.

Using Procmon64.exe against the Code.Exe helped identify this.

Solution was to move to an area on the physical disk.

Sheelah answered 15/5, 2023 at 9:15 Comment(0)
L
0

For most people, the culprit will be some extension. But extensions are often very useful for linting, auto completion, formatting etc. So, removing extensions altogether is not an option. But uninstall all unnecessary extensions, anyway.

Some tips will help to reduce this CPU usage. All we have to do is reduce the load for extensions.

  1. Split large files containing code into smaller files so that when making changes to a files, extensions won't have to parse and process large files.
  2. Reduce imports in code as much as possible so that extensions won't have to deal with too many imports.
  3. Press Command + Shift + P (or Ctrl + Shift + P in windows and linux) and type >Local History: Delete All and press Enter. This will clear all local history of files which will make some extensions faster.
  4. Open only a single project in VS Code at a time. (do not open a parent folder of the project's folder instead)

These steps are effective if you are working on large projects.

Loudspeaker answered 9/10, 2023 at 17:54 Comment(0)
A
0

I'd recommend going through https://github.com/microsoft/vscode/wiki/Performance-Issues#consuming-cpu. What follows is an attempt at summary, but I'd suggest you just go read the thing directly.

The asker of this question had the same performance with extensions disabled, but if that isn't the case for you, you can use the builtin process monitor (Help > Open Process Explorer) to see if any extensions are consuming more CPU than the others (look at the "extensionHost" process to see if it's using a lot of CPU). To try reloading with extensions disabled, use the Developer: Reload With Extensions Disabled command in the command palette. You can also do an extension bisect to try to figure out what extension is causing it.

If it's not caused by an extension, you can get more info by running code --status in a terminal/shell while VS Code is already open. From the output of that command, you can get info about whether the CPU consumption is from the renderer/window process, the shared process, etc.

Artless answered 9/10, 2023 at 21:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.