System.Linq.Parallel is missing optimizations for IReadOnlyList<T> and IReadOnlyCollection<T>
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
# Description
`PartitionedDataSource.InitializePartitions` only checks for `IList` here: https://github.com/dotnet/runtime/blob/732f597ad3b75f1384eefa10cf5484ce3b221087/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Partitioning/PartitionedDataSource.cs#L85-L146
`ScanQueryOperator` has paths specifically for `IList` but not `IReadOnlyList` here https://github.com/dotnet/runtime/blob/732f597ad3b75f1384eefa10cf5484ce3b221087/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/ScanQueryOperator.cs#L61 and here https://github.com/dotnet/runtime/blob/732f597ad3b75f1384eefa10cf5484ce3b221087/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/ScanQueryOperator.cs#L100
`ParallelEnumerable.Count` only uses the count from `ICollection` and not `IReadOnlyCollection` here https://github.com/dotnet/runtime/blob/732f597ad3b75f1384eefa10cf5484ce3b221087/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs#L1855 and here https://github.com/dotnet/runtime/blob/732f597ad3b75f1384eefa10cf5484ce3b221087/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs#L1926
This looks like some holdover from the pre-netfx4.5 days. Consumers really shouldn't have to implement `IList` with all the modifying members throwing exceptions for every read-only collection just to get better performance from PLINQ.
Contributor guide
Assessment
This issue has not been assessed yet.