Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module import performance regression #2336

Merged
merged 6 commits into from
May 6, 2023
Merged

Conversation

fflaten
Copy link
Collaborator

@fflaten fflaten commented Apr 9, 2023

PR Summary

Fix module import perf regression in 5.4.0 (went from <1 sec to 4sec) caused by slow Get-Help calls introduced in #2170.

Affected inline-builds (releases) primarily because Get-Help reparses the whole command source (17k+ lines psm1 when inline) to get comment-based help. See #2335

This PR replaces the code with an internal function to set the help-message.

PR also includes a minor update to help-text for operator-specific parameters.

Fix #2335

PR Checklist

  • PR has meaningful title
  • Summary describes changes
  • PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • Tests are added/update (if required)
  • Documentation is updated/added (if required)

Require internal flag to add parameter help for
built-in Should-operators. Only used by command ref-script in
docs-repo and increased import time by 3-4sec in inline build.
See pester#2335
@fflaten
Copy link
Collaborator Author

fflaten commented Apr 9, 2023

Any suggestions? This is really ugly hotfix, regardless of env var (existing pattern) vs module parameter. Revert the whole docs-feature?
Update: Rewrote PR to use internal helper-function instead to avoid complexity with env-variables etc. Duplicate synopsis atm, but now it's easily customizable.

Ideally we'd use external help (and markdown as source?), but that requires cleanup here and docs-repo (incl. Alt3.Docusaurus.PowerShell module) so need to discuss it first. That should also improve speed of Get-ShouldOperator which also uses Get-Help internally.

src/Main.ps1 Outdated
$ParameterAttribute.HelpMessage = 'The name of the assertion/operator'
$AttributeCollection.Add($ParameterAttribute)

$ValidateSetAttribute = & $SafeCommands['New-Object']System.Management.Automation.ValidateSetAttribute($script:AssertionOperators.Keys)

Check notice

Code scanning / PSScriptAnalyzer

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.
src/Main.ps1 Outdated
$ValidateSetAttribute = & $SafeCommands['New-Object']System.Management.Automation.ValidateSetAttribute($script:AssertionOperators.Keys)
$AttributeCollection.Add($ValidateSetAttribute)

$RuntimeParameter = & $SafeCommands['New-Object'] System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)

Check notice

Code scanning / PSScriptAnalyzer

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.
src/Main.ps1 Outdated
)
DynamicParam {
$ParameterName = 'OperatorName'
$RuntimeParameterDictionary = & $SafeCommands['New-Object'] System.Management.Automation.RuntimeDefinedParameterDictionary

Check notice

Code scanning / PSScriptAnalyzer

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.
src/Main.ps1 Outdated
DynamicParam {
$ParameterName = 'OperatorName'
$RuntimeParameterDictionary = & $SafeCommands['New-Object'] System.Management.Automation.RuntimeDefinedParameterDictionary
$AttributeCollection = & $SafeCommands['New-Object'] System.Collections.ObjectModel.Collection[System.Attribute]

Check notice

Code scanning / PSScriptAnalyzer

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.
src/Main.ps1 Outdated
$ParameterName = 'OperatorName'
$RuntimeParameterDictionary = & $SafeCommands['New-Object'] System.Management.Automation.RuntimeDefinedParameterDictionary
$AttributeCollection = & $SafeCommands['New-Object'] System.Collections.ObjectModel.Collection[System.Attribute]
$ParameterAttribute = & $SafeCommands['New-Object'] System.Management.Automation.ParameterAttribute

Check notice

Code scanning / PSScriptAnalyzer

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.

The built-in *-Object-cmdlets are slow compared to alternatives in .NET. To fix a violation of this rule, consider using an alternative like `foreach/for`-keyword etc.`.
@fflaten fflaten added the Bug label Apr 11, 2023
@fflaten fflaten marked this pull request as ready for review April 11, 2023 21:31
@nohwnd nohwnd merged commit c5dd825 into pester:main May 6, 2023
@fflaten fflaten deleted the import-patch1 branch May 6, 2023 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Another Performance report between v4 and v5 :-)
2 participants