wpf icon indicating copy to clipboard operation
wpf copied to clipboard

Replace PartialList with ReadOnlyCollection

Open ThomasGoulet73 opened this issue 4 months ago • 0 comments

Description

ReadOnlyCollection does the same thing as PartialList but it's more optimized due to the fact that it does not support wrapping a range of a list and instead just forwards the read-only call to the wrapped list. It's also better to use a collection from the BCL than our own where possible.

I also removed the constructor that allowed passing a list without a range to discourage the use of PartialList when we don't need the range feature and I removed an unused static method in PartialList.

Here's benchmark where I do a foreach on PartialList vs ReadOnlyCollection:

| Method             | Mean     | Error    | StdDev   | Ratio | Gen0   | Allocated | Alloc Ratio |
|------------------- |---------:|---------:|---------:|------:|-------:|----------:|------------:|
| PartialList        | 34.57 ns | 0.334 ns | 0.313 ns |  1.00 | 0.0043 |      72 B |        1.00 |
| ReadOnlyCollection | 20.38 ns | 0.181 ns | 0.161 ns |  0.59 | 0.0024 |      40 B |        0.56 |

Customer Impact

Better perf.

Regression

No.

Testing

Local testing.

Risk

Low.

Microsoft Reviewers: Open in CodeFlow

ThomasGoulet73 avatar Oct 03 '24 23:10 ThomasGoulet73