question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Powershell initialization on linux is slow

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
lzybkrcommented, Aug 20, 2016

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.

0reactions
SRGOMcommented, Jun 8, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[SOLVED] powershell extremely slow to load
Hello,. I am running powershell-bin from AUR, the current version 7.3.1. I find that it is extremely slow to launch the interactive shell ......
Read more >
PowerShell steps to fix slow startup
When PowerShell starts to become slow at startup, an update of the .NET framework might be the cause. To speed up again, use...
Read more >
Remote power shell very slow from Linux to Windows
Remote power shell very slow from Linux to Windows ... I'm running Ubuntu 20 and PowerShell 7.1, Apt upgrade comes up empty.
Read more >
Optimizing your $Profile - PowerShell Team
Your PowerShell Profile allows you to customize your PowerShell session and runs at startup. Complex profiles can cause a significant delay ...
Read more >
Calling powershell.exe is extremely slow
Try using ngen.exe (Native Image Generator) to precompile the assemblies that Powershell loads during startup.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found