Skip to content

Commit dc659f5

Browse files
SP3269sdwheeler
andauthored
Add a note about array addition to the "PowerShell scripting performance considerations" page (MicrosoftDocs#12106)
* Add a note about array addition * Update script-authoring-considerations.md * Update script-authoring-considerations.md --------- Co-authored-by: Sean Wheeler <[email protected]>
1 parent d836460 commit dc659f5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ $results += Get-SomethingElse
113113
$results
114114
```
115115

116+
>[!NOTE]
117+
> In PowerShell 7.5, array addition was optimized and no longer creates a new array for each
118+
> operation. The performance considerations described here still apply to PowerShell versions
119+
> prior to 7.5. For more information, see [What's New in PowerShell 7.5][01].
120+
116121
Array addition is inefficient because arrays have a fixed size. Each addition to the array creates
117122
a new array big enough to hold all elements of both the left and right operands. The elements of
118123
both operands are copied into the new array. For small collections, this overhead may not matter.
@@ -880,21 +885,22 @@ Iterations Test TotalMilliseconds RelativeSpeed
880885
- [Add-Member][18]
881886

882887
<!-- Link reference definitions -->
888+
[01]: ../../whats-new/what-s-new-in-powershell-75.md#engine-improvements
883889
[02]: ../../learn/deep-dives/everything-about-hashtable.md
884890
[03]: ../../learn/deep-dives/everything-about-null.md
885891
[04]: xref:System.Void
886892
[05]: xref:Microsoft.PowerShell.Core.Out-Null
887893
[06]: xref:System.Collections.Generic.List`1
888-
[07]: xref:System.Collections.Generic.List`1.Add*
894+
[07]: xref:System.Collections.Generic.List`1.Add%2A
889895
[08]: xref:System.String
890896
[09]: xref:System.Int32
891897
[10]: xref:System.Object
892-
[11]: xref:System.Collections.Generic.List`1.ToArray*#system-collections-generic-list-1-toarray
898+
[11]: xref:System.Collections.Generic.List%601.ToArray%2A#system-collections-generic-list-1-toarray
893899
[12]: xref:System.Collections.ArrayList
894900
[13]: /powershell/module/microsoft.powershell.core/about/about_join
895901
[14]: xref:System.Text.StringBuilder
896902
[15]: xref:System.IO.StreamReader
897-
[16]: xref:System.IO.File.ReadLines*
903+
[16]: xref:System.IO.File.ReadLines%2A
898904
[17]: xref:Microsoft.PowerShell.Utility.Write-Host
899905
[18]: xref:Microsoft.PowerShell.Utility.Add-Member
900906
[19]: /powershell/module/microsoft.powershell.core/about/about_hash_tables#creating-ordered-dictionaries

0 commit comments

Comments
 (0)