-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
I discovered that for cdxml modules PowerShell calls GetSaferPolicy() method twice:
moduleInfo = LoadModule(file, moduleBase: null, prefix: string.Empty, ss: null, ref options, flags, out found); ExternalScriptInfo scriptInfo = GetScriptInfoForFile(file, out moduleName, true);
Dozens of such modules can be installed on the system and this gives a noticeable delay in the command.
Get-Module -Listavailable -All can consumes a lot of time - up to 25s on my computer at first run and up to 12s in follow runs.
After I remove GetSaferPolicy() - up to 9s at first run and up to 0.9s in follow runs
GetScriptInfoForFile() method has a checkExecutionPolicy parameter which is converted to CommandOrigin in GetScriptInfoForFile() method but the CommandOrigin is ignored in follow method ShouldRunInternal() - so checkExecutionPolicy parameter doesn't work at all.
I hope we could find a way to remove the extra second check for cdxml modules. I'd expect that we could get 10% perf win at least in the scenario on Windows.
/cc @PaulHigin @SteveL-MSFT
Steps to reproduce
Get-Module -Listavailable -AllEnvironment data
Name Value
---- -----
PSVersion 7.0.0-preview.2
PSEdition Core
GitCommitId 7.0.0-preview.2-36-g3ca5a1bdb031eeb9453b1481bcfa23eee6d89aec
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0