You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pwsh is 2 times slower than powershell to load #6443
Reacted by Trần Ngọc Khoa, soul4soul, J.B., Soheil Alizadeh, inv2004, Panna ABDUL HAKIM, Himanshu Bansal, Jason Wei, Klaus Jokisuo, Naimul Islam and 5 more
Looks like assemblies are being crossgen'd. However, getting many messages from crossgen.exe that certain things aren't supported, which means those methods stay as MSIL (which probably explains why the assembly says it's MSIL). This also means that the MSIL needs to be JIT on startup. I think this is what's impacting the startup performance. We'll need to continue this investigation to see if anything we can do here.
Reacted by Keith Hill, Christoph Bergmeister, ExE Boss, Yupei Liu and Joel Bennett
It would be great to have better startup time since custom profiles add on top of that. But honestly, PowerShell easily makes up those seconds when it comes to getting stuff done (not only in terms of time to run but also the time to write the code/command) 😄
Reacted by Kwezilomso Mhaga, Jacques Rimbault, Ryan MacLean and Aleksandr Flawrist
It would be great to have better startup time since custom profiles add on top of that. But honestly, PowerShell easily makes up those seconds when it comes to getting stuff done (not only in terms of time to run but also the time to write the code/command) 😄
Honestly, this is not a very good argument. Same thing could be said about windows start up times or python start up times. First time to boot/startup is pretty important.
Reacted by Kwezilomso Mhaga, Carl Walsh, tsukumi, Aleksandr Flawrist and Conor Dockry
On the other hand, cmd.exe is a native exe that does next to nothing on startup. pwsh.exe is a managed exe that sets up a complex execution environment.
We should of course strive to improve the startup performance, but comparing to completely different environments with very diffrent capabilities is not really relevant.
Reacted by Christoph Bergmeister, Ryan and ExE Boss
On the other hand, cmd.exe is a native exe that does next to nothing on startup. pwsh.exe is a managed exe that sets up a complex execution environment.
We should of course strive to improve the startup performance, but comparing to completely different environments with very diffrent capabilities is not really relevant.
Agreed, which is why I included Powershell 6 and Python 3 performance relative to CMD. It seems that powershell should be able to be within 2-3 times the startup speed of CMD, putting it in line with other interactive languages.
Agreed, which is why I included Powershell 6 and Python 3 performance relative to CMD. It seems that powershell should be able to be within 2-3 times the startup speed of CMD, putting it in line with other interactive languages.
Being 'interactive' is just one trait of many. The environments are very different.
PowerShell has an adaptable type system that abstracts many different underlying type systems. It has an extensible formatting system that renders objects to text. It has an object based pipeline. It has an adaptable prompt, tab completion etc.
All of these takes time to initialize, especially the extensible types and formatting systems.
As Steve said, there is an issue with the assemblies not being crossgen-ed as they should, so we spend quite a lot of extra time jitting IL. That must be fixed.
But even with that fixed, there are differences in scope and the dependencies on the CLR/DLR that will make powershell slower to start than cmd and python.
I would venture to guess that if python were to have a more expressive REPL and a deep framework available and ready to use on the first line, its load times would be on-par with pwsh. I have seen plenty of python scripts with long init times due to dependency loading for more advanced uses. Python starts fast by default because it loads with less available by default. Comparing the start times between PowerShell and other shells and scripting languages is a bit hard to do unless they are all closer in default feature parity. none of the languages I have experience with come with as mush on-by-default as PowerShell does (for better or worse).
One idea is to do the jitting the first time the function is called (which will make the first time to actually call the function slow, but subsequent calls fast). In addition to this, a set of frequently utilized functions can be precompiled/jitted functions on startup.
The testing here is all without loading a profile (-NoProfile) and looking at startup times of a shell of almost 1 second. I would consider even 0.1 second as being a tad on the slow side.
Version
Startup Time
5
0.3s
6.2.3
4.5s
7.0.2
0.6s
Mind you that with plugins enabled startup will suffer even more. I have two plugins enabled: PoshGit and Z-AutoJump. My startup time with these two plugins is:
As someone, who has pwsh as his default shell under linux, this greatly affects me, so I would much appreciate any possible improvement! Not only is launching a terminal window noticeably slower, but I just cannot have quick powershell scripts run on my hotkeys. (Which I have quite a few of that I rely on, since I'm using sway as a window manger.)
I need to go back to bash or perl for these purposes, which are much more infuriating to write stuff in, than powershell, which is in my opinion a much better system overall, that's why I'm sticking to it, even though there are quite a few small inconveniences. (Such as for example the '<' file redirection operator missing, which is expected by some programs, such as vim, but luckily it can be fixed by telling it to use pipes instead.)
Anyway, some updates that make pwsh -c viable for more or less instantaneous small things would be very welcome!
Thanks for all the work of the development team, my life is already much better by having a shell with proper syntax and programmability (e.g. the | % { } foreach and such things are awesome! That same thing would be so much more complicated in bash...) instead of the "everything's just text, use cut, sed, awk, grep, ..." mess that all the POSIX compatible shells are!
István Donkó (@isti115) Fundamental problem is that managed runtime initialization is significantly slower than native code. .Net team made many improvements but managed will never be as fast as native at startup.
In the repo performance improvements was also made. I do not think we can make more in the milestone.
Cheat: you can create and run simple C# infinite service with one function - load all PowerShell dlls.
(As result all dlls will be already in memory before you run PowerShell)
(For the service you can use PowerShell too - run and Start-Sleep -Seconds 65535.)
Hmm, reading all the suggestions I came up with the idea of a simple PowerShell script running continuously in the background reading a FIFO as it's input and executing whatever commands get piped in there. I know that this is a very messy solution, because variables and contexts could get mixed up, but if I am careful enough when writing the commands and ensure that they have no side effects (I mean, in terms of the execution context, otherwise it would make no sense to run the commands at all. 😄) this could work.
We started new wave of startup scenario optimizations in #14268. Join us for contributing, reviewing and testing!
Also we expect many improvements for .Net 6.0 from .Net team - we will benefit from this automatically.
Dear fellows, I am tired that PS 5.1 currently installed on my Windows 7 x64 (please, don’t even mention W10) is unable to properly execute BOM-less *.ps1 with UTF8 strings (e.g. $singer = "Björk"; echo $singer outputs as BjГ¶rk). That's why I downloaded both (portable) PS 6.2.7 and 7.2.0p7 and run as follows pwsh.exe .\test.ps1. Indeed, they have no problem outputting UTF8, but the execution time is 2x slower: 320ms (5) vs 694ms (7) vs 760ms (6). Delay is noticeable and annoying.
I am not a developer to grasp all the aforementioned mumbo jumbo on why the progress turned into regress, but I remember there was a trick to make early versions of PS run faster by ngen install. Is there something similar here, or we're doomed?
Activity
[-]pwsh is almost 3 times slower than powershell to load[/-][+]pwsh is 2 times slower than powershell to load[/+]SteveL-MSFT commentedon Mar 21, 2018
Looks like assemblies aren't being crossgen'd so startup time is affected by JIT
SteveL-MSFT commentedon Mar 21, 2018
Looks like assemblies are being crossgen'd. However, getting many messages from crossgen.exe that certain things aren't supported, which means those methods stay as MSIL (which probably explains why the assembly says it's MSIL). This also means that the MSIL needs to be JIT on startup. I think this is what's impacting the startup performance. We'll need to continue this investigation to see if anything we can do here.
musm commentedon Mar 21, 2018
Honestly even powershell 5 is very slow (6 times slower) than CMD. It would be good to have powershell 6 within 2~3 times the speed of cmd.
For example on my computer python is only 2 times slower than CMD to start...
bergmeister commentedon Mar 24, 2018
It would be great to have better startup time since custom profiles add on top of that. But honestly, PowerShell easily makes up those seconds when it comes to getting stuff done (not only in terms of time to run but also the time to write the code/command) 😄
musm commentedon Mar 25, 2018
Honestly, this is not a very good argument. Same thing could be said about windows start up times or python start up times. First time to boot/startup is pretty important.
powercode commentedon Mar 25, 2018
On the other hand, cmd.exe is a native exe that does next to nothing on startup. pwsh.exe is a managed exe that sets up a complex execution environment.
We should of course strive to improve the startup performance, but comparing to completely different environments with very diffrent capabilities is not really relevant.
musm commentedon Mar 25, 2018
We should of course strive to improve the startup performance, but comparing to completely different environments with very diffrent capabilities is not really relevant.
Agreed, which is why I included Powershell 6 and Python 3 performance relative to CMD. It seems that powershell should be able to be within 2-3 times the startup speed of CMD, putting it in line with other interactive languages.
powercode commentedon Mar 26, 2018
Being 'interactive' is just one trait of many. The environments are very different.
PowerShell has an adaptable type system that abstracts many different underlying type systems. It has an extensible formatting system that renders objects to text. It has an object based pipeline. It has an adaptable prompt, tab completion etc.
All of these takes time to initialize, especially the extensible types and formatting systems.
As Steve said, there is an issue with the assemblies not being crossgen-ed as they should, so we spend quite a lot of extra time jitting IL. That must be fixed.
But even with that fixed, there are differences in scope and the dependencies on the CLR/DLR that will make powershell slower to start than cmd and python.
markekraus commentedon Mar 26, 2018
I would venture to guess that if python were to have a more expressive REPL and a deep framework available and ready to use on the first line, its load times would be on-par with
pwsh. I have seen plenty of python scripts with long init times due to dependency loading for more advanced uses. Python starts fast by default because it loads with less available by default. Comparing the start times between PowerShell and other shells and scripting languages is a bit hard to do unless they are all closer in default feature parity. none of the languages I have experience with come with as mush on-by-default as PowerShell does (for better or worse).musm commentedon Mar 30, 2018
One idea is to do the jitting the first time the function is called (which will make the first time to actually call the function slow, but subsequent calls fast). In addition to this, a set of frequently utilized functions can be precompiled/jitted functions on startup.
32 remaining items
Bouke commentedon Jul 9, 2020
The testing here is all without loading a profile (
-NoProfile) and looking at startup times of a shell of almost 1 second. I would consider even 0.1 second as being a tad on the slow side.Mind you that with plugins enabled startup will suffer even more. I have two plugins enabled: PoshGit and Z-AutoJump. My startup time with these two plugins is:
Compare that with startup times on macOS (iTerm):
musm commentedon Jul 9, 2020
Bouke Haarsma (@Bouke) totally agree. Note, posh-git is notoriously bad for adding at least 500ms to the start time.
And yes even 1 second is a ridiculous start time for an interactive shell. Start times need to get under 100ms for the best UX.
isti115 commentedon Jul 16, 2020
As someone, who has pwsh as his default shell under linux, this greatly affects me, so I would much appreciate any possible improvement! Not only is launching a terminal window noticeably slower, but I just cannot have quick powershell scripts run on my hotkeys. (Which I have quite a few of that I rely on, since I'm using sway as a window manger.)
I need to go back to bash or perl for these purposes, which are much more infuriating to write stuff in, than powershell, which is in my opinion a much better system overall, that's why I'm sticking to it, even though there are quite a few small inconveniences. (Such as for example the '<' file redirection operator missing, which is expected by some programs, such as vim, but luckily it can be fixed by telling it to use pipes instead.)
Anyway, some updates that make
pwsh -cviable for more or less instantaneous small things would be very welcome!Thanks for all the work of the development team, my life is already much better by having a shell with proper syntax and programmability (e.g. the
| % { }foreach and such things are awesome! That same thing would be so much more complicated in bash...) instead of the "everything's just text, use cut, sed, awk, grep, ..." mess that all the POSIX compatible shells are!iSazonov commentedon Jul 16, 2020
István Donkó (@isti115) Fundamental problem is that managed runtime initialization is significantly slower than native code. .Net team made many improvements but managed will never be as fast as native at startup.
In the repo performance improvements was also made. I do not think we can make more in the milestone.
Cheat: you can create and run simple C# infinite service with one function - load all PowerShell dlls.
(As result all dlls will be already in memory before you run PowerShell)
(For the service you can use PowerShell too - run and Start-Sleep -Seconds 65535.)
musm commentedon Jul 16, 2020
Can parts of the initialization be done after the REPL is started?
iSazonov commentedon Jul 16, 2020
I think REPL is more for C# scripts.
For PowerShell there is a hosting idea from Jason but it is not easy to implement I guess.
isti115 commentedon Jul 21, 2020
Hmm, reading all the suggestions I came up with the idea of a simple PowerShell script running continuously in the background reading a FIFO as it's input and executing whatever commands get piped in there. I know that this is a very messy solution, because variables and contexts could get mixed up, but if I am careful enough when writing the commands and ensure that they have no side effects (I mean, in terms of the execution context, otherwise it would make no sense to run the commands at all. 😄) this could work.
iSazonov commentedon Dec 3, 2020
We started new wave of startup scenario optimizations in #14268. Join us for contributing, reviewing and testing!
Also we expect many improvements for .Net 6.0 from .Net team - we will benefit from this automatically.
joeyaiello commentedon Dec 7, 2020
Closing in favor of the more actionable issue that Ilya (@iSazonov) wrote (thanks!), #14268
This is something we should always strive to improve, but I think this thread has gone somewhat stale in terms of actionable technical info.
flawrist commentedon Jul 4, 2021
Dear fellows, I am tired that PS 5.1 currently installed on my Windows 7 x64 (please, don’t even mention W10) is unable to properly execute BOM-less *.ps1 with UTF8 strings (e.g.
$singer = "Björk"; echo $singeroutputs as BjГ¶rk). That's why I downloaded both (portable) PS 6.2.7 and 7.2.0p7 and run as followspwsh.exe .\test.ps1. Indeed, they have no problem outputting UTF8, but the execution time is 2x slower: 320ms (5) vs 694ms (7) vs 760ms (6). Delay is noticeable and annoying.I am not a developer to grasp all the aforementioned mumbo jumbo on why the progress turned into regress, but I remember there was a trick to make early versions of PS run faster by
ngen install. Is there something similar here, or we're doomed?