Skip to content

Add "Avoid function / scriptblock based recursion" section to Performance Considerations document #11037

Description

@iRon7

Type of issue

Missing information

Feedback

Knowing that PowerShell functions are quite expensive (see: https://stackoverflow.com/a/75722847/1701026) it is better to avoid recursion as per helpful StackOverflow answer from Santiago Squarzon (@santisq):

The recommended approach would be to traverse your nested objects using a Stack or Queue (or their generic counterparts Stack<T> and Queue<T>).

Page URL

https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/performance/script-authoring-considerations?view=powershell-7.4

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md

Author

Sean Wheeler (@sdwheeler)

Document Id

9818d91b-8c5f-337a-f5e1-7a40abd5fd1a

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions