129

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

David Buck
  • 3,752
  • 35
  • 31
  • 35
Adriel Werlich
  • 1,982
  • 5
  • 15
  • 30
  • @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 – Matt Bierner Dec 07 '18 at 05:05
  • @mattbierner, thanks for that, it was my understanding. – jessehouwing Dec 07 '18 at 06:46
  • 1
    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). – Álvaro González Dec 07 '18 at 17:02
  • VSCode is great! It´s very responsive.... – Adriel Werlich Mar 24 '19 at 20:14
  • @Adriel How much space does your installation of VSC take ? – Trunk Aug 24 '19 at 16:14
  • @Trunk... how would I found that info reliably? At `C:\Users\adrie\AppData\Local\Programs\Microsoft VS Code` it says `225 MB (236.912.640 bytes)` size in disk. – Adriel Werlich Aug 27 '19 at 05:23
  • @Adriel : Yes - if no add-ons are accepted. Nice toggle buttons on the slim left-hand panel too. Wish Sublime Text had something like that. Took a bit of messing to get Emmet going though - this *should* work straight out of the box. – Trunk Aug 27 '19 at 12:04
  • That's nothing. When I open a C++ project, VS Code occupies 15 GB of memory. I have to use a swap file on my 16 GB laptop. – facetus Aug 27 '22 at 16:22

6 Answers6

166

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.

Matt Bierner
  • 58,117
  • 21
  • 175
  • 206
  • 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... – Adriel Werlich Dec 07 '18 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 Mar 29 '19 at 18:05
  • 15
    @mattbierner the linked "performance guide" does not address memory at all. It seems to assume all VSCode performance issues are CPU issues. – Slack Flag Jun 24 '19 at 16:33
  • 3
    Hi @Matt, I was just curious so as to why MS has choosen JS to develop vs code? – logdev Jul 14 '20 at 05:58
  • 1
    @SyedSouban It looks like Microsoft hates making POSIX system calls, they like to use Windows SDK. So they didn't make Visual Studio for Linux. – Akib Azmain Turja Nov 14 '20 at 10:58
  • 2
    One file open window always use up above 200Mbytes memory, I really couldn't understand why. – Clock ZHONG Nov 19 '20 at 11:15
49

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
} 
Cengkuru Michael
  • 4,590
  • 1
  • 33
  • 33
  • 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 – FindOutIslamNow Nov 24 '20 at 14:54
  • 1
    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. – Thiago Ruiz Jan 20 '21 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... – user3658510 Feb 12 '22 at 20:54
  • 1
    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. – user3658510 Feb 12 '22 at 21:36
39

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

itzcompeter
  • 407
  • 4
  • 3
  • This is not causing problems at all, instead the extensions YOU INSTALL can cause the bad effects – FindOutIslamNow Nov 24 '20 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. – Benyamin Limanto Mar 24 '22 at 08:58
30

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

  • 9
    that is correct, web is not made for desktop application development – Alex Jones Dec 17 '19 at 06:26
  • 3
    can someone explain the downvotes? Doesn't Electron pack with Chromium and Node.js? – Prid Apr 23 '20 at 02:06
  • 2
    @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. – Finn Shadow May 08 '20 at 21:30
  • 21
    @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 May 12 '20 at 04: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 May 28 '20 at 11:56
  • 1
    yep , for those who uses laptop as programming driver, this has bad impact on battery too. – Programmer Dancuk Jul 28 '20 at 09:02
  • I could argue that any editor environment which uses any amount of resources is fine, for example a google datacenter computer with 10TB memory and 1024 cores with 8192 threads as my "development machine". This is not an argument, not in 2020 and not in 2070 when everbody has such a machine. There is no reason that any software uses 200MB for text files which have a size of <2MB! – Quonux Oct 25 '20 at 19:21
  • @Quonux "There is no reason that any software uses 200MB for text files which have a size of <2MB" Hahahaha, so true. – Programmer Dancuk Nov 02 '20 at 11:46
  • 1
    This is not causing problems at all, instead the extensions YOU INSTALL can cause the bad effects – FindOutIslamNow Nov 24 '20 at 14:52
  • So Sad, VSCode has a lot of perks, still can't leave it. is there a way? – Jovylle Mar 25 '22 at 02:44
  • @JovylleBermudez the only way if you still love VScode is : Upgrade your hardware. Thats the only realistic way so VS Code perform faster and better. Also , choose wisely extensions to install, disable auto update, selective indexing, etc etc. – Programmer Dancuk Mar 31 '22 at 04:47
5

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
FindOutIslamNow
  • 1,169
  • 1
  • 14
  • 33
4

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

roshnet
  • 1,695
  • 18
  • 22