Why does VS Code require so much memory? How can I make it run more memory-efficiently? - visual-studio-code

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.

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
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.

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
}

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

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

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

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

Related

Typescript & Javascript language features extension in VSCode causes my laptop to overheat

It's been like a month since I started using VSCode and I like it.
However, The problem is the moment I launch the program the laptop's fans start to make relatively loud sounds so I thought because there were multiple programs running at once but after trying to launch VSCode alone the problem remains untacked.
Here's what I've tried so far:
Disabled the gpu accelartion.
Disabled all the built-in extensions except the Typescript & Javascript language features extension (I didn't install any additional extensions)
Tried clean install.
Nothing worked, But when I tried to disable Typescript & Javascript language features extension the fans started to cool down. I even checked the system monitor. The reading of CPU usage for VSCode before and after disabling the mentioned extension
It jumped from 0% to 28% to 30% to 16% and keeps bouncing between 9% and 16% for as long as the application is running.
I know it seems obvious to disable this extension and I'm good to go but I need it, I mean the whole point of me using VSCode is this extension. Did anyone run into the same problem or it's only me?
P.S: I'm using Ubuntu 18.04 LTS.
So after decades of research this guy's answer solved the problem.
All you have to do is to open VSCode then File > Preferences > Settings then type the following in the search bar typescript.disableAutomaticTypeAcquisition then check the checkbox and you're good to go.
However, autocomplete is not working for some imported packages so be aware of that.
Anyway, I opened an issue long time ago if anyone wants to follow any new updates about this topic here.
Go and give this guy's answer a thumbs up or love because he deserves it.

How to investigate VS Code taking 30% of CPU although it is supposed to do nothing

My CPU is oscillating between 20 and 30% usage for CPU usage based on Windows Task manager. it is occurring for several hours now.
I expect this VS Code instance to do nothing.
How can I investigate what is going wrong?
I tried to open "Developer: Toggle Developer Tools", then go to performance tab and record. Unfortunately it is reporting that most of the time is in "idle" (which is what I would expect)
(I also tried to ask on Twitter without success https://twitter.com/apupier/status/1100348567926071296)
regards,
Based on the comments it seems that what the Task Manager reports is the total use of VS both on CPU utilization and memory.
A broad range of reasons could explain the observations you made.
1.Increased CPU and Memory usage by VS Studio.
2. Increased Fan Speed.
3. Your code being idle.
It can be the case that the VS Code or one of its plugins is actually doing something even if you do not actively use it. For sure if it is opened, even without being used the program will use some memory.
You can find more information on the CPU usage per VS Code Extension by typing: code --status in the command line. You can also try to execute: code --disable-extensions to run VS Code without any extensions to see if the CPU/Memory usage is reduced.
Results of the code --status will look like this
There are some related issues you could also see in GitHub, I checked before writing this answer:
100% core CPU usage without apparent reason
Excess CPU usage
Excess CPU usage editing C file
It is usually an extension. E.g. Python Intellisense. It is perhaps outsourcing processing for some scientific project aimed for the good of humanity. Fingers crossed.
Update 2022:
Earlier you could find them easily with VS Codes builtin Process Explorer. Help > "Open Process Explorer."
But the newer versions are very sneaky. They seem to have evolved making them difficult to catch while stealing your cpu. Disclaimer: the behavior may very well be even an unintentional glitch although it does not appear so.
Can you catch it in action?
Its as tough as catching a fly. As of Feb 2022, the moment you attempt to probe into the cpu usage either via vs code "help/Open Process Explorer" OR sometimes even win task manager, it stops/vanishes like a fly. Then it stays inactive for some hours or a day. You forget about it and get busy coding only to find the fans are going crazy because it has sneaked in to be active again. The newer version of the bug is perhaps programmed as such.
None the less with a lot of patience, you can sometimes catch them. Here is one instance and yet it vanished before i could scroll to catch the name.
VS Code Process manager
Solution:
I don't have a reason to probe it beyond a limit, but a small monitoring script should be able to catch the culprit.
Personally, I just had to remove the "Python extension for Visual Studio Code (Python IntelliSense - Pylance)" and that was enough to resolve.
IDE's a notoriously expensive to run. As soon as you open VS Code it loads the program from your hard drive, into RAM; acting as a staging point for all the processes VS Code uses to manage its environment. Things like,
Overhead of the Electron framework upon which it is built
Checking for external file changes that need to be synchronized to the editor
Render pipeline
Child processes to support any extensions you have running
Terminal instances (and by extension anything running in those terminals)
Here's a nifty little extension I found after some quick Googling. It will show you the subprocesses running in VS Code, and may help you identify exactly what is taking up the most bandwidth. Do keep in mind, that by killing some of those processes, you may begin to lose the associated functionality, and indeed possibly even cause VS Code to crash. The only sure-fire way to keep it from taxing your CPU, is to shut it down completely when you're not using it.
Perhaps you could try out another IDE like Sublime, IntelliJ, or Atom and see if they act more as you expect when idle. Personally, I really love the features of Jetbrain's IntelliJ (and similar: Webstorm, PhpStorm, etc).
I got the same problem. It might have something to do with the git operations. You might have DELETED many projects from your current folder, while git didn't register the deletion.
When you do something with the changes, git operations will use a lot of CPU.
The simplest solution is to create a new folder and start running VSCode in it. You can delete the whole old folder, or you can leave it alone. It's up to you.

VSCode slow to open and highlight large log files

VSCode slow to open and highlight large log files
I use VSCode to open large log files with the log highlighter syntax. These log files are very large, often a couple hundred megabytes. I switched from Notepad++ to VSCode for all the features. Notepad++ usually opened the files okay but lacked the highlighting benefits.
The new VSCode updates asked me to increase memory size which I quadrupled.
However some logs either take a while to highlight or never do at all.
Is there anyway to either speed this up or get this to work a bit better? Should I open a github issue?
I would really like to use VSCode for these logs but it is annoying...
Resources on PC are not an issue.

My Visual studio 2013 typing and scrolling is slow. What Can i do?

I'm Currently working on Visual studio 2013 (MVC 5). Since few days I'm getting a problem with typing and scrolling, database is connecting slow. But all working fine but slowly.
Problems:
When typing a letter that keyword display taking long time and some
times not displayed.
Scrolling the solution explorer does not response correctly.
Connect the Database is not showing the connection string.
I searched on the internet and found smooth scroll plugin. After installing that it worked for some hours only after that getting same problem
Apart from Visual Studio 2013 Update 5 which will play an important role here you can also check other solutions listed below.
For smooth scrolling you could try the below steps :
For smooth scrolling install this extension
In VS Go Tools > Environment > General.
My Install had the "Automatically adjust visual experience based on client performance" checked which was using software-accelerated rendering. I unchecked this and checked "Use hardware graphics acceleration if available".
Restart VS
Slow building, debugging, navigating ?
Why is VS 2013 very slow?
More references :
MSDN
You need to check two things: CPU load and drive load. Open the Task Manager and observe the CPU load to determine if the problem is due to the CPU is being overloaded. Watch the HDD LED to see if it flashing rapidly or on and solid to see if the problem is due to the hard-drive is being thrashed (and thus overloaded). Both can cause this symptom. If you find either to be the case, then your next step is to figure out why the system is being burdened.
if 0% CPU and 0% disk. But any text editing heavily lags? Must be due to some sort of plugin or something. I know the CodeLens, Insights, and Microsoft Git have had issues reported with slow IDE response.
Also try disabling Synchronized Settings in VS. Go to Tools -> Options -> Environment-Synchronized Settings and remove this option by un-checking the check box.
Update your Visual Studio get working normally.
https://www.visualstudio.com/en-us/news/vs2013-update5-vs.aspx

netbeans optimize disk usage

Is there some way to optimize the Netbeans IDE for PHP (and Symfony)? It's very good with code hinting, debugging etc, but the downside is that while writing code, the disk works intensively all the time which is disturbing and besides the editor slows down slightly because of the code hinting. I have 8GB memory, so it would be quite sufficient for all Netbeans needs. I mean, is it possible to somehow limit the disk usage but without limiting the code hinting? E,g, make it load all code hints to memory.
Here is a workaround which solves the problematic symptoms, i.e. the NetBeans editor now works without small delays from code hinting and the disk is quiet. I installed RAMDisk with 500MB capacity. Then I moved the .netbeans folder with user files to this RAMDisk, as described in wiki.netbeans.org/FaqWhatIsUserdir. Just FYI, moving the project folder itself made no difference, only .netbeans folder was necessary to move.
Try to deactivate the Local History plugin, maybe it is causing the high disk usage.
(Be careful if you don't have any vcs)
Although I've never have a problem with Netbeans and disk usage, maybe your disk is broke.
Kudos to #camcam for answering his own question and posting the RAM disk suggestion. In case there are other Mac users out there who want to do this on a Mac, here are instructions:
1) Create a 500MB RAM disk:
diskutil erasevolume HFS+ 'NetBeansRAMDisk' `hdiutil attach -nomount ram://1048576`
2) Locate the NetBeans application in the Finder, control-click on it and select "Show Package Contents"
3) Add this line to Contents/Resources/NetBeans/etc/netbeans.conf:
netbeans_default_cachedir="/Volumes/NetBeansRAMDisk"
(Note: the cachedir option was added in NetBeans 7.1.)
For more info, see:
http://bogner.sh/2012/12/os-x-create-a-ram-disk-the-easy-way/
http://wiki.netbeans.org/FaqAlternateUserdir
I have been using NetBeans since version 3.x I have never seen it access the disk all the time. I have regularly ~20 projects open with ~350.000 LOC
You should first make sure it's actually NetBeans that does the disk access (on Windows you can do this with ProcessExplorer, don't know about Linux).
If it's really NetBeans, you could try to give it more memory to cache more data in memory. See the NetBeans FAQ for details
And of course make sure your system is not swapping because you have too many programs open (even though it's very unlikely with 8GB RAM but not unseen...).
If you already configured NetBeans to use more memory, maybe you gave it too much and that's why the system is swapping (just a thought).
Is your project stored in Subversion? Do you use TortoiseSVN? With he default installation TortoiseSVN has a background process that caches information about the status of your versioned files. I have seen that scanning the whole harddisk in the background...