Skip to content

Double check cdxml modules in Safer API #10309

@iSazonov

Description

@iSazonov

I discovered that for cdxml modules PowerShell calls GetSaferPolicy() method twice:

  1. moduleInfo = LoadModule(file, moduleBase: null, prefix: string.Empty, ss: null, ref options, flags, out found);
  2. 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 -All

Environment 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performance

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions