Command discovery on systems with symlinks to slow filesystems is slow
Not all commands. ls takes 20 seconds. dir is nearly instant. This is just the simplest example, but the overall experience makes me want to stop using powershell on Linux. :-( Tab completion also takes around 20 seconds.
Steps to reproduce
PS > measure-command { ls }
Days : 0
Hours : 0
Minutes : 0
Seconds : 20
Milliseconds : 25
Ticks : 200252179
TotalDays : 0.000231773355324074
TotalHours : 0.00556256052777778
TotalMinutes : 0.333753631666667
TotalSeconds : 20.0252179
TotalMilliseconds : 20025.2179
PS > measure-command { dir }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 3
Ticks : 33095
TotalDays : 3.83043981481481E-08
TotalHours : 9.19305555555556E-07
TotalMinutes : 5.51583333333333E-05
TotalSeconds : 0.0033095
TotalMilliseconds : 3.3095
Expected behavior
ls takes a second or so.
Actual behavior
ls takes 20 seconds.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0-preview.1
PSEdition Core
GitCommitId v6.1.0-preview.1
OS Linux 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02)
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
@SteveL-MSFT We have a perf regression on Windows. For Get-Command ping ~3 ms on my system.
Test script:
for ($i=0; $i -lt 2000; $i++) {
Get-Command ping > $null
}
On Windows PowerShell 5.1 and up to PowerShell Core 6.1.0-Preview2 I get ~2.5 sec. Starting with PowerShell Core 6.1.0-Preview2 I get ~8.2 sec.
I compare traces for PowerShell Core 6.1.0-Preview2 and PowerShell Core 6.1.0-Preview3

You can see that there other P/Invokes are used in Preview3. I guess it was a change in .Net Core. If so I guess they know about this and accepted consciously.
Should we worry about this or can we ignore it?
Update: Maybe on Unix we have have the same root of the regression?
@iSazonov yes, PATHEXT is a Windows only thing. On non-Windows, the executable bit is what is interesting although we special case .ps1. The perf data is different from what this issue is discussing which is specific to traversing symlinks opening files at discovery time rather than at runtime.
@SteveL-MSFT Thanks! Clear about PATHEXT.
My trace is for discovery code. I think just the enumeration (Directory.EnumerateFiles()) is slow, not exec bit check. Our exec bit check is on last step for single file (after we enumerate all files in a directory and filter by name) so if we remove them it does not help.
@bendowski @SurferJeffAtGoogle Please download compiled artifact from #10815 and look if you see any perf change.
@iSazonov Can you open a corefx issue about Directory.EnumerateFiles()? That perf regression is really bad and not expected.
@0xd4d PowerShell repo steps is not useful for Core team. This requires a C# repo. I didn't have time to check it out (on different .Net Core versions).
@iSazonov I opened a corefx issue about that problem https://github.com/dotnet/corefx/issues/41898
I'm sorry for the delay. I tried the build you linked as well as the latest preview (7.0.0-preview5) and they seem to behave the same. It's much better than before (with ls taking 20 seconds), but still some commands take longer than I would expect. This seems to be somewhat non-deterministic, see this example of running "true" 4 times in a row:
PS /> measure-command { true }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 28
Ticks : 289087
TotalDays : 3.34591435185185E-07
TotalHours : 8.03019444444444E-06
TotalMinutes : 0.000481811666666667
TotalSeconds : 0.0289087
TotalMilliseconds : 28.9087
PS /> measure-command { true }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 443
Ticks : 4435776
TotalDays : 5.134E-06
TotalHours : 0.000123216
TotalMinutes : 0.00739296
TotalSeconds : 0.4435776
TotalMilliseconds : 443.5776
PS /> measure-command { true }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 34
Ticks : 346932
TotalDays : 4.01541666666667E-07
TotalHours : 9.637E-06
TotalMinutes : 0.00057822
TotalSeconds : 0.0346932
TotalMilliseconds : 34.6932
PS /> measure-command { true }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 422
Ticks : 4221326
TotalDays : 4.88579398148148E-06
TotalHours : 0.000117259055555556
TotalMinutes : 0.00703554333333333
TotalSeconds : 0.4221326
TotalMilliseconds : 422.1326
Doing the same with trace-command confirms the additional ~400ms is spent in /usr/bin:
DEBUG: 2019-10-24 13:53:38.2773 CommandDiscovery Information: 0 : Looking for true.ps1 in /usr/sbin
DEBUG: 2019-10-24 13:53:38.2784 CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: 2019-10-24 13:53:38.2785 CommandSearch Information: 0 : WriteLine Current patterns exhausted in current directory: /usr/sbin
DEBUG: 2019-10-24 13:53:38.2785 CommandDiscovery Information: 0 : Looking for true in /usr/bin
DEBUG: 2019-10-24 13:53:38.6796 CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: 2019-10-24 13:53:38.6798 CommandDiscovery Information: 0 : Looking for true.ps1 in /usr/bin
DEBUG: 2019-10-24 13:53:38.6914 CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: 2019-10-24 13:53:38.6914 CommandSearch Information: 0 : WriteLine Current patterns exhausted in current directory: /usr/bin
Would love to see if someone could reproduce this one again on .NET 5 with the latest version of Win10. I know a ton of work has been done around filesystem access and symlinks in both of those products.
Just noting that this issue still seems to be present on the latest PowerShell 7.1.
I tried to install PowerShell 7 on my gLinux host today. Unfortunately, it's too slow at the moment for me to switch to using PowerShell on Linux. I did try modifying path as @bendowski suggested, but still experienced this issue.
Happy to provide more logs as necessary and help troubleshoot, as I imagine others have/will experience the same issues.
The latest PowerShell 7 on my Windows corp workstation (20H2) does not experience this issue.
Happy to provide more logs as necessary and help troubleshoot, as I imagine others have/will experience the same issues.
@TsekNet I have already prepared some fixes. There is already open PR (one from some follow). But we have no resources to make this work fast. We need more code reviewers and developers. MSFT team introduce Working Groups (you can read in their PowerShell blog). You could take participation in related WG if you have an interest.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.