PowerShell-Docs
PowerShell-Docs copied to clipboard
Add "Avoid function / scriptblock based recursion" section to `Performance Considerations` document
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 @santisq:
The recommended approach would be to traverse your nested objects using a
Stack
orQueue
(or their generic counterpartsStack<T>
andQueue<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
@sdwheeler
Document Id
9818d91b-8c5f-337a-f5e1-7a40abd5fd1a