Skip to content

switch from newing up a ICollection ot a IReadOnlyCollection #12008

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ttstanley
Copy link
Contributor

@ttstanley ttstanley commented Jun 12, 2025

Context

There were lots of allocations due to newing up a ReadOnlyCollection just to fufill a ICollection contract even if it was internal.
image

Changes Made

  • For internal usage I moved over to returning IReadOnlyCollection instead of creating a new ReadOnlyCollection that can be used with ICollection.
  • For public api's that couldn't change I waited till the actual return time to create a ReadOnlyCollection
    image

Testing

Took traces of build before my changes and after my changes.
Before (ReadOnlyCollection 33 Megs of allocations)
image

After (ReadOnlyCollection 5 Megs of allocations)
image

Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant