Skip to content

Stop boxing WeakReferenceListEnumerator in PresentationSource use#6502

Merged
singhashish-wpf merged 1 commit intodotnet:mainfrom
stephentoub:stopboxingWeakReferenceListEnumerator
Jul 21, 2022
Merged

Stop boxing WeakReferenceListEnumerator in PresentationSource use#6502
singhashish-wpf merged 1 commit intodotnet:mainfrom
stephentoub:stopboxingWeakReferenceListEnumerator

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Apr 29, 2022

Description

PresentationSource.CriticalCurrentSources is internal and is only ever foreach'd by consumers. It's strongly-typed to return IEnumerable, but the actual WeakReferenceList it returns has a struct-based enumerator, which means each foreach boxes that enumerator. By changing CriticalCurrentSources to return WeakReferenceList rather than IEnumerable, those foreach's can bind directly to the struct, with all the benefits that brings.

Customer Impact

Unnecessary allocation

Regression

No

Testing

CI

Risk

Minimal

Microsoft Reviewers: Open in CodeFlow

PresentationSource.CriticalCurrentSources is internal and is only ever foreach'd by consumers.  It's strongly-typed to return IEnumerable, but the actual WeakReferenceList it returns has a struct-based enumerator, which means each foreach boxes that enumerator.  By changing CriticalCurrentSources to return `WeakReferenceList` rather than `IEnumerable`, those foreach's can bind directly to the struct, with all the benefits that brings.
@stephentoub stephentoub requested a review from a team as a code owner April 29, 2022 13:53
@ghost ghost assigned stephentoub Apr 29, 2022
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Apr 29, 2022
@ghost ghost requested review from SamBent, dipeshmsft and singhashish-wpf April 29, 2022 13:53
@singhashish-wpf singhashish-wpf merged commit 81ddc95 into dotnet:main Jul 21, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants