From 69b8082d39ad21a3056028b64b48f1466922521d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slav=20Pidgorny=20=F0=9F=87=BA=F0=9F=87=A6?= Date: Mon, 26 May 2025 13:23:56 +1000 Subject: [PATCH 1/3] Add a note about array addition --- .../performance/script-authoring-considerations.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md b/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md index 9d14e399bf7a..c1304a7c0de7 100644 --- a/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md +++ b/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md @@ -113,6 +113,8 @@ $results += Get-SomethingElse $results ``` +>[!NOTE] In PowerShell 7.5, array addition has been optimized and no longer creates a new array for each operation. The performance considerations described here should only be used in environments where PowerShell versions prior to 7.5 are in use. For more information, see [What's New in PowerShell 7.5](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-75?view=powershell-7.5#engine-improvements). + Array addition is inefficient because arrays have a fixed size. Each addition to the array creates a new array big enough to hold all elements of both the left and right operands. The elements of both operands are copied into the new array. For small collections, this overhead may not matter. From d1fd5df06b7fa8ab50c12a9acccf0df3ac6d8ef9 Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Mon, 26 May 2025 09:13:22 -0500 Subject: [PATCH 2/3] Update script-authoring-considerations.md --- .../performance/script-authoring-considerations.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md b/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md index c1304a7c0de7..d61f2de02fbb 100644 --- a/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md +++ b/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md @@ -113,7 +113,10 @@ $results += Get-SomethingElse $results ``` ->[!NOTE] In PowerShell 7.5, array addition has been optimized and no longer creates a new array for each operation. The performance considerations described here should only be used in environments where PowerShell versions prior to 7.5 are in use. For more information, see [What's New in PowerShell 7.5](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-75?view=powershell-7.5#engine-improvements). +>[!NOTE] +> In PowerShell 7.5, array addition was optimized and no longer creates a new array for each +> operation. The performance considerations described here still apply to PowerShell versions +> prior to 7.5. For more information, see [What's New in PowerShell 7.5][01]. Array addition is inefficient because arrays have a fixed size. Each addition to the array creates a new array big enough to hold all elements of both the left and right operands. The elements of @@ -882,21 +885,22 @@ Iterations Test TotalMilliseconds RelativeSpeed - [Add-Member][18] +[01]: ../whats-new/what-s-new-in-powershell-75.md#engine-improvements [02]: ../../learn/deep-dives/everything-about-hashtable.md [03]: ../../learn/deep-dives/everything-about-null.md [04]: xref:System.Void [05]: xref:Microsoft.PowerShell.Core.Out-Null [06]: xref:System.Collections.Generic.List`1 -[07]: xref:System.Collections.Generic.List`1.Add* +[07]: xref:System.Collections.Generic.List`1.Add%2A [08]: xref:System.String [09]: xref:System.Int32 [10]: xref:System.Object -[11]: xref:System.Collections.Generic.List`1.ToArray*#system-collections-generic-list-1-toarray +[11]: xref:System.Collections.Generic.List%601.ToArray%2A#system-collections-generic-list-1-toarray [12]: xref:System.Collections.ArrayList [13]: /powershell/module/microsoft.powershell.core/about/about_join [14]: xref:System.Text.StringBuilder [15]: xref:System.IO.StreamReader -[16]: xref:System.IO.File.ReadLines* +[16]: xref:System.IO.File.ReadLines%2A [17]: xref:Microsoft.PowerShell.Utility.Write-Host [18]: xref:Microsoft.PowerShell.Utility.Add-Member [19]: /powershell/module/microsoft.powershell.core/about/about_hash_tables#creating-ordered-dictionaries From 88f26f24f7b489072949c8bd8ceae98708ce2ed3 Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Mon, 26 May 2025 09:18:50 -0500 Subject: [PATCH 3/3] Update script-authoring-considerations.md --- .../performance/script-authoring-considerations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md b/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md index d61f2de02fbb..2e6895cd0421 100644 --- a/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md +++ b/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md @@ -885,7 +885,7 @@ Iterations Test TotalMilliseconds RelativeSpeed - [Add-Member][18] -[01]: ../whats-new/what-s-new-in-powershell-75.md#engine-improvements +[01]: ../../whats-new/what-s-new-in-powershell-75.md#engine-improvements [02]: ../../learn/deep-dives/everything-about-hashtable.md [03]: ../../learn/deep-dives/everything-about-null.md [04]: xref:System.Void