Skip to content

Replace PartialList with ReadOnlyCollection #9890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ThomasGoulet73
Copy link
Contributor

@ThomasGoulet73 ThomasGoulet73 commented Oct 3, 2024

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 ThomasGoulet73 requested review from a team as code owners October 3, 2024 23:22
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Oct 3, 2024
@ThomasGoulet73 ThomasGoulet73 force-pushed the replace-PartialList-with-ReadOnlyCollection branch from 3becc71 to 9d53be9 Compare December 28, 2024 03:09
@ThomasGoulet73
Copy link
Contributor Author

I rebased on main to fix the conflicts.

…tialList-with-ReadOnlyCollection

# Conflicts:
#	src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs
@ThomasGoulet73
Copy link
Contributor Author

I pulled main to fix the conflicts.

…tialList-with-ReadOnlyCollection

# Conflicts:
#	src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs
@ThomasGoulet73
Copy link
Contributor Author

I pulled main to fix the conflicts.

Copy link
Contributor

@himgoyalmicro himgoyalmicro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@himgoyalmicro himgoyalmicro merged commit 3a3e2a3 into dotnet:main Feb 19, 2025
8 checks passed
@himgoyalmicro
Copy link
Contributor

Thank you @ThomasGoulet73 for your continuous contributions 😄

@ThomasGoulet73
Copy link
Contributor Author

Thanks

@ThomasGoulet73 ThomasGoulet73 deleted the replace-PartialList-with-ReadOnlyCollection branch February 20, 2025 04:12
@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants