Powershell: Extremely high memory usage

Created on 13 Jul 2019  ·  22Comments  ·  Source: PowerShell/PowerShell

Steps to reproduce

Run pwsh.exe

Expected behavior

The shell should open quickly and use very little memory.

Actual behavior

The shell opens, doesn't get to the prompt very quickly, then once running each pwsh.exe process uses rougly 250Mb of RAM (!!!)
For daily use this is not acceptable when compared to my typical shell workflow.

Environment data

Loading personal and system profiles took 2136ms.
PS C:\projects> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.1
PSEdition                      Core
GitCommitId                    6.2.1
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Question Resolution-Answered

All 22 comments

PowerShell is .Net Core application and this assumes Core runtime initialization that consume more resources (memory, CPU and startup time) than any application on native code.
Also PowerShell depends on that user put in PowerShell profile.

We continuously track startup delay. Now 7.0 preview has better startup time than 6.2/6.1 versions.

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Yeesh, I step away from vacation and the issue is bot-closed. :)

This response is alarming to me. Is PowerShell meant to be used as an interactive shell? Everyone (including MS) seems to be moving away from cmd.exe to powershell. And if I use the system powershell I'm given a message from MS to try this new PSCore you're working on....

It's unbelievable to me that anybody would seriously suggest using a shell that uses 200Mb(!!!) per open window/tab. How can anyone realistically justify this?

@photex I just checked PS 7-preview1 -- it uses ~ 95 MB on open, and reaches the prompt much quicker than 6.2 does. Already a pretty big improvement, and I've noted several performance-oriented PRs since preview1 came out. @SteveL-MSFT tweeted yesterday that we will probably see the preview2 release today, so I would re-check when that is made available and see if you notice a marked difference.

There are ongoing efforts to improve performance. @iSazonov do we currently have a tracking issue for performance / memory usage?

do we currently have a tracking issue for performance / memory usage?

It makes no sense. We should track only _specific scenarios_ which we can reproduce, find critical code and improve it. Feel free to open such issues.
Preview2 comes with .Net Core 3.0 Preview6 where GC works very good now.

It's unbelievable to me that anybody would seriously suggest using a shell that uses 200Mb(!!!) per open window/tab. How can anyone realistically justify this?

PowerShell is __Power__ Shell, not native code shell. For the power we have to pay. You can continue to use cmd.exe and VBS for simple scenarios to consume few resources.

I'd reckon high memory usage for a shell that's sitting idle to be a very specific and trackable issue. I'd love to see this situation improve.

As cool as it may be, it's not worth the price of entry as a daily use shell. If you're honestly cool with your idle terminals consuming over a Gb of RAM then more Power to you.

It's not consuming > 1GB of RAM when idle. While I appreciate it's perhaps not ideal for you, I don't think that exaggerating the issue is perhaps the best way to get something done about it. 😕

PowerShell has a bit of a disadvantage there when it comes to comparing it with other shells, partially because it utilizes .NET's libraries. While there are things we can do to limit startup memory usage, some of those libraries we need to work with are surprisingly large.

I do, however, agree that idle memory usage is a fairly reproducible issue, especially if we're talking right after startup. Scripts / code that is run after that may cause additional libraries to be loaded, and I'm not sure if .NET Core has quite gotten library _unloading_ sorted out completely -- and from what I've read I think there would need to be improvements in the engine to support unloading of unused libraries as well.

I'm not exaggerating and it appeared at one point that I'm your target audience.

When I'm working on windows I might have up to 7 tabs running. Windows Terminal or Consolez, etc. On Linux systems I routinely run 5 or more shells in tmux over ssh.

I noticed the high usage because of this. My terminal reported over a Gb of Ram being used. The guilty party was that every single instance of pwsh.exe was using 250Mb.

And yes that is even when idle. There are plenty of terminal power users running on systems other than windows, routinely running 5 to 6 shells under tmux or iterm and so on. Powershell could not be used by these users.

Hmm, PS7 does seem to be a bit (2x) more of a hog than 6.2. This is after startup of PS7:

image

@rkeithhill is that preview1?

Curious to see how preview2 turns out. 🙂

Yes, and same here. To be fair, it is preview and perhaps there is more perf work to be done to bring the size down. Plus they are adding support for WPF/WinForms, so that might be adding to the size.

Maybe, but I wouldn't think WPF/WinForms libraries should be being loaded unless the code running actually needs it? 🤔

Ok I've tracked down the major consumer of RAM which was the AWS tools for PsCore.

The AWS tools for standard powershell have not had this impact for whatever reason. I can use the python tools until that's resolved.

This puts things back into a ballpark where it doesn't seem so crazy! And now it is more clear why you thought I was exaggerating (250Mb is a far far cry from 30Mb - 50mb).

@vexx32 Yeah, you're right. Those assemblies are not loaded initially in preview1. As for loaded assemblies, all I see are two new ones (and one removed) in v7 preview1 (vs 6.2.1):

InputObject                                    SideIndicator
-----------                                    -------------
Microsoft.Management.Infrastructure.Native.dll =>
Markdig.dll                                    =>
System.ValueTuple.dll                          <=

Combined "file size" is < 600 KB.

@photex Does AWS PowerShell have a repo / forum for reporting issues with the module? Might be worth pinging them and asking why the memory increase for PS Core is so much more than it was for 5.1 🙂

I did a brief search but it was time to head to dinner. Will pick it up tomorrow because I absolutely think this should be discussed. :D

Ok I've tracked down the major consumer of RAM which was the AWS tools for PsCore.

If it uses Web cmdlets from PowerShell Core it is known issue and we have a tracking issue(s) for them (web cmdlets consume a lot of memory)

@chuanjiao10 Let's not teasing

@chuanjiao10 Please share specific scenarios with simple repo so that we could measure and then find a fix.

I was getting similar RAM usage to this issue, and I discovered that it was due to a couple of plugins I had installed such as “PowerShell Humanizer” and “Communary.ConsoleExtensions”. It seems that even just putting a couple of things in your profile can really expand memory usage. I'm not sure if this is due to the plugins themselves being sloppy with RAM usage, or if it has to do with the nature of loading modules in PowerShell itself.

@Serentty You need to be more specific. If you think a problem is in PowerShell then open new issue with a description/repro steps. If you think that the problem is in a module, then open the issue in its repository.

Well sure, I'm just +1ing what the OP said. In case anyone else is experiencing really high RAM usage, check your profile to see if there's something in there that's responsible.

Was this page helpful?
0 / 5 - 0 ratings