149

Does anyone know how to make VS Code use less memory?

It´s taking more than 2gb, sometimes more than 3 gigabytes to have some 8 files opened.

enter image description here

8
  • @jessehouwing That information is wrong and not helpful. VS Code and Atom are separate editors that are both built on the Electron framework. And neither Electron nor sandboxing entails high memory usage Commented Dec 7, 2018 at 5:05
  • @mattbierner, thanks for that, it was my understanding. Commented Dec 7, 2018 at 6:46
  • 2
    Well, it's an editor built on top of a web browser. It's only thanks to some absolutely brilliant minds that it can even exist. However, you must have some module or extension gone berserk. For instance, screenshot shows that Intelephense is indexing—that should only take a few seconds (no idea of how long the editor has been running). Commented Dec 7, 2018 at 17:02
  • VSCode is great! It´s very responsive.... Commented Mar 24, 2019 at 20:14
  • @Adriel How much space does your installation of VSC take ?
    – Trunk
    Commented Aug 24, 2019 at 16:14

6 Answers 6

189

I'm on the VS code team.

There are many possible causes for high memory usage. We've put together tools and a guide that can help you investigate potential performance issues.

Start by using the process explorer. The process explorer shows the cpu and memory usage per child process of VS Code. Open it with the Open process explorer command. The process explorer should help you track down which processes are using the most memory. Often times, an extension will turn out to be the root cause

enter image description here

Also, even though you have only opened eight files, your workspace seems to be quite a bit larger than just those eight. Providing intellisense and other advanced editor features often requires processing many unopened files as well. Whether or not the 2-3gb is justified or not is hard to say without understanding what extensions you are using and what your workspace contains.

I recommend that you also take a look through the rest of our performance issue guide. It explains how to report performance issues and further investigate performance problems.

7
  • 2
    yes @MattBierner, thanks for the reply. I´ve tryied to disable some extensions and close some of the files I had openned in the workspace, but even the memory usage was still quite high... I´ll try to follow some of the guidelines you traced here, and later on I´ll give the feedback... Commented Dec 7, 2018 at 11:52
  • 1
    Hi. My instance also consumes a lot of memory. The most is "gpu-process" (nearly 500-550 MB), however, I use it for developing Angular application. Is it ok, that gpu-process consumes so many memory? My screen resolution is 2736x1824.
    – Vlad
    Commented Mar 29, 2019 at 18:05
  • 17
    @mattbierner the linked "performance guide" does not address memory at all. It seems to assume all VSCode performance issues are CPU issues.
    – Slack Flag
    Commented Jun 24, 2019 at 16:33
  • 3
    Hi @Matt, I was just curious so as to why MS has choosen JS to develop vs code?
    – logdev
    Commented Jul 14, 2020 at 5:58
  • 3
    One file open window always use up above 200Mbytes memory, I really couldn't understand why. Commented Nov 19, 2020 at 11:15
64

You could prevent vscode from watching folders with really many files in you project by adding this to your json settings file

"files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/node_modules/**": true
} 
5
  • 2
    I found that these two enteries are already added by default. However, some extension I was using was having a problem that it maybe ingoring these settings and scanning whole project and causing bad effects Commented Nov 24, 2020 at 14:54
  • 2
    my vscode was using 2.5G on a workspace with a lot of go packages and the kernel src folder. After adding this config it went down to 300 MB of ram used. Thanks. Commented Jan 20, 2021 at 14:58
  • I disabled all the extensions, but even then vs code was using more than 2 gb of ram in a little test project. Adding files.watcherExclude to the user settings immediately reduced ram usage to 400 mb. They were already on by default, but somehow they were being ignored. As a test, i later removed the setting and vs code was still obeying the default and maintained a low ram usage. I still don't know what happened... Commented Feb 12, 2022 at 20:54
  • 2
    Edit: The problem was from the default js/ts language extension using all the ram. Unfortunately i still didn't found a solution to the issue. Commented Feb 12, 2022 at 21:36
  • 2
    You could also add build, output etc folders Commented Jun 5 at 9:42
49

It's because VS Code isn't a native program like Vim, Emacs, or even Sublime. Opening VS Code is like opening another Chrome window, it uses a lot of RAM, and CPU.

Neovim uses around 10 mbs of RAM (with some plugins), while vs code uses 700 mbs of RAM, with no file opened

2
  • This is not causing problems at all, instead the extensions YOU INSTALL can cause the bad effects Commented Nov 24, 2020 at 14:53
  • I do agree, with same level of Addons on GVIM, I can have a free estate so much better than on VS Code, just sometimes when code in C#, to do any import automatically, Vim lack some, sometimes I just go back and forth because of it. Commented Mar 24, 2022 at 8:58
37

Because VSCode is built on top of Electron, so under the hood it is just the same as web browser. If you need more lighter memory use Sublime Text or Notepad++ instead

11
  • 9
    that is correct, web is not made for desktop application development
    – Alex Jones
    Commented Dec 17, 2019 at 6:26
  • 3
    can someone explain the downvotes? Doesn't Electron pack with Chromium and Node.js?
    – Prid
    Commented Apr 23, 2020 at 2:06
  • 3
    @Prid These days, Electron (which does include Chromium and Node.js) isn't very much heavier than a native app. There are still some people who believe that they are huge ram-sucking monstrosities, but that is simply not the case. Commented May 8, 2020 at 21:30
  • 25
    @FinnShadow could you please cite some sources or benchmark tests for latest version Electron apps VS native apps performance being the same? Notepad++ is using 12MB with 20 files open on my computer vs Visual Studio Code using 120MB for 4 files open and 3 extensions installed.
    – Prid
    Commented May 12, 2020 at 4:00
  • 1
    @FinnShadow Electron certainly adds some 10 or 100 MB, this happens in e.g. the Slack App or VS Code. For some that additional memory consumption isn't much (it doesn't matter on my 32 Gig development machine) but for others it can become critical (on a 2 Gig tablet for example)
    – Marged
    Commented May 28, 2020 at 11:56
9

Check if your extensions are causing the bad things

I have used the guide https://github.com/Microsoft/vscode/wiki/Performance-Issues#profile-the-running-extensions

to know why VS Code was

  • very slow to startup
  • taking much ram (3-4 gb)

You can create a CPU profile and share it in the issue with the extension author or us. To create a CPU profile:

  • Close all instances of VSCode and start with code --inspect-extensions=9993 or any other port number.
  • Execute the Developer: Show Running Extensions Command. This command opens an editor with all the running extensions. To start recording a profile

I found some extension with high delays and they were marked with unresponsive yellow triangle. I disabled them using right click context menu, restarted VS Code, and after that it

  • Takes only a few seconds to startup
  • Takes only ~250mb of ram
8

Not an actual solution, but launching VSC via code ./ --disable-extensionscan do so without requiring to manually disable all of them.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.