Use Span to fill List<T> in more ToList scenarios#86796
Use Span to fill List<T> in more ToList scenarios#86796eiriktsarpalis merged 8 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsAdds span-based filling of
Secondary improvements:
Fixes #80760
|
|
Thanks. Can you share some benchmarks that demonstrate these improvements are meaningful, in particular in the places that are requiring a lot of code to be added, like in AppendPrepend1Iterator? |
Upon more careful review, the added complications in Append/Prepend were mostly not worth it. Missing the optimizations in I'll add benchmarks on some of the other changes shortly. BenchmarkDotNet=v0.13.2.2052-nightly, OS=Windows 11 (10.0.22621.1776) PowerPlanMode=00000000-0000-0000-0000-000000000000 Arguments=/p:EnableUnsafeBinaryFormatterSerialization=true IterationTime=250.0000 ms
|
|
Here are some benchmarks of some other cases. BenchmarkDotNet=v0.13.2.2052-nightly, OS=Windows 11 (10.0.22621.1776) PowerPlanMode=00000000-0000-0000-0000-000000000000 Arguments=/p:EnableUnsafeBinaryFormatterSerialization=true IterationTime=250.0000 ms
|
src/libraries/System.Linq/src/System/Linq/AppendPrepend.SpeedOpt.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Linq/src/System/Linq/AppendPrepend.SpeedOpt.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.SpeedOpt.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.SpeedOpt.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Stephen Toub <[email protected]>
Co-authored-by: Stephen Toub <[email protected]>
|
Are there any further changes required on this? |
eiriktsarpalis
left a comment
There was a problem hiding this comment.
LGTM @brantburnett, apologies for the delay in review. Before we get this merged, any chance you could remove the singleton optimization since it doesn't appear to be contributing substantially?
Sure, I'll try to get it done today. |
Adds span-based filling of
List<T>during calls toToListusingCollectionsMarshal.SetCountto the following additional scenarios:ToListof aUnionorDistinctToListof aLookup<TKey, TElement>including cases within groupingToListof aSelectprojection against anIPartition(i.e. sorted)ToListof anOrderedEnumerablereturning a single element (i.e.Skip/Takeapplied to a sorted list for a single result)ToListofAppendandPrependscenarios, mostly multiple appends/prependsSecondary improvements:
ToArrayof an emptyLookup<TKey, TElement>now usesArray.EmptyToListof multiplePrependoperations no longer allocates an intermediate arrayFixes #80760