Skip to content

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented May 1, 2022

Description

Use a Dictionary instead of Hashtable in UniqueEventHelper in order to avoid boxing the ref count integer on every add/remove. And as long as this was being updated, addressed the TODO to combine the identical types into a helper base type that provided most of the functionality shared instead of being duplicated on both the generic and non-generic handler implementation. Also reduced the allocation in InvokeEvents, just allocating an array for the handlers rather than allocating a complete copy of the dictionary, a keys object, and an enumerator object. And avoid forcing the delegates dictionary into existence just to remove a delegate.

Customer Impact

Unnecessary allocation

Regression

No

Testing

CI

Risk

Minimal

Microsoft Reviewers: Open in CodeFlow

Use a Dictionary instead of Hashtable in UniqueEventHelper in order to avoid boxing the ref count integer on every add/remove.  And as long as this was being updated, addressed the TODO to combine the identical types into a helper base type that provided most of the functionality shared instead of being duplicated on both the generic and non-generic handler implementation.  Also reduced the allocation in InvokeEvents, just allocating an array for the handlers rather than allocating a complete copy of the dictionary, a keys object, and an enumerator object.
@stephentoub stephentoub requested a review from a team as a code owner May 1, 2022 02:31
@ghost ghost assigned stephentoub May 1, 2022
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label May 1, 2022
@ghost ghost requested review from SamBent, dipeshmsft and singhashish-wpf May 1, 2022 02:31
@dipeshmsft dipeshmsft merged commit 021e1ad into dotnet:main Apr 3, 2023
@stephentoub stephentoub deleted the uniqueeventhandler branch April 3, 2023 13:13
@ghost ghost locked as resolved and limited conversation to collaborators May 4, 2023
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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants