Consider preferring AddRange over CopyTo for collection-expressions of List type #71216
Labels
Area-Compilers
Code Gen Quality
Room for improvement in the quality of the compiler's generated code
Feature - Collection Expressions
Milestone
Spun-off from #71195
See the following simple test case, which has IL size 66 for the Span/CopyTo strategy and 18 for the AddRange strategy.
Perf of these two strategies appears to be similar per #70656 (comment).
Note that using AddRange and SetCount/AsSpan together may be problematic. I think whenever you add to the list you need to call AsSpan again for example. And, uses of SetCount would need to be adjusted.
Since we already prefer AsSpan for collection expressions created from lists without spreads, it's possible that CopyTo is still overall better for uniformity/sanity here.
The text was updated successfully, but these errors were encountered: