Powershell: Powershell initialization on linux is slow

Created on 19 Aug 2016  Â·  5Comments  Â·  Source: PowerShell/PowerShell

Steps to reproduce

Launch powershell

Expected behavior

Usable prompt in milliseconds

Actual behavior

Usable prompt in seconds

Environment data

PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.9
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

For example:

[me@ipsum] ~
➜  cat test.ps1
#!/usr/bin/powershell
exit
[me@ipsum] ~
➜  time ./test.ps1
./test.ps1  1.30s user 0.12s system 138% cpu 1.035 total

Compared to:

[me@ipsum] ~
➜  cat test.sh
#/bin/bash
exit
[me@ipsum] ~
➜  time ./test.sh
./test.sh  0.00s user 0.00s system 0% cpu 0.002 total

The windows host I have available:

PS C:\Users\me> echo "exit" > test.ps1
PS C:\Users\me> Measure-Command {.\test.ps1}


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 7
Ticks             : 71141
TotalDays         : 8.23391203703704E-08
TotalHours        : 1.97613888888889E-06
TotalMinutes      : 0.000118568333333333
TotalSeconds      : 0.0071141
TotalMilliseconds : 7.1141



PS C:\Users\me> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      3.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.18033
BuildVersion                   6.2.9200.16434
PSCompatibleVersions           {1.0, 2.0, 3.0}
PSRemotingProtocolVersion      2.2
Resolution-Fixed WG-Engine-Performance

Most helpful comment

At least some of the perf issue will be addressed by #1846.

Note that your example on Windows:

PS C:\Users\me> Measure-Command {.\test.ps1}

does not accurately measure the startup costs of PowerShell because PowerShell has already started. It would be more accurate to use:

PS C:\Users\me> Measure-Command { powershell -nop -file .\test.ps1}

I did a ton of work in Windows PowerShell v5.1 on startup, and this scenario would run in the 200-300ms range, still a lot slower than I'd like, but a vast improvement over Windows PowerShell 5.0 which was closer to 900ms.

All 5 comments

At least some of the perf issue will be addressed by #1846.

Note that your example on Windows:

PS C:\Users\me> Measure-Command {.\test.ps1}

does not accurately measure the startup costs of PowerShell because PowerShell has already started. It would be more accurate to use:

PS C:\Users\me> Measure-Command { powershell -nop -file .\test.ps1}

I did a ton of work in Windows PowerShell v5.1 on startup, and this scenario would run in the 200-300ms range, still a lot slower than I'd like, but a vast improvement over Windows PowerShell 5.0 which was closer to 900ms.

Thanks for pointing that out, and you are correct. For completeness and to correct the above misleading times:

PS C:\Users\me> Measure-Command { powershell -nop -file .\test.ps1}


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 221
Ticks             : 2218809
TotalDays         : 2.56806597222222E-06
TotalHours        : 6.16335833333333E-05
TotalMinutes      : 0.003698015
TotalSeconds      : 0.2218809
TotalMilliseconds : 221.8809

222 milli is more indicative to the 'real' launch time I was seeing. Should I close this pending that item? I'm assuming that #1846 is the equivalent of running ngen on a windows host?

Just wanted to add here for Linux. I'm on Arch using the latest AppImage. On a 5/10
powerful computer, I'm getting the following

time powershell -c 'exit'

1.32s user 0.16s system 88% cpu 1.658 total

On my Ubuntu16.04 box:

steve@slee-ubuntu16:~$ time powershell -c 'exit'

real    0m0.602s
user    0m0.632s
sys 0m0.076s
steve@slee-ubuntu16:~$ 

https://github.com/PowerShell/PowerShell/pull/3787 really helped with the startup time.

I just downloaded Beta2 AppImage and on my system the user times went down from 1.6s to 1.0s- huge improvements.

Keep going!

PS: I'm confused by how linux time command works, I'd have thought user/sys times would be times spent in respective spaces and real would be a sum of the two.

Was this page helpful?
0 / 5 - 0 ratings