Skip to content
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

Avoid Hashtable-related allocations in AccessorTable #6500

Merged
merged 1 commit into from
Aug 12, 2022

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Apr 29, 2022

Description

Use a strongly-typed Dictionary instead.

  • The key is a struct. Every time an item is added to the table or a lookup into the table is performed, the key is getting boxed. Using Dictionary avoids all this boxing.
  • The struct key lacks a strongly-typed Equals. Every comparison results in a boxing. Gave the key a strongly-typed Equals.
  • Every cleanup operation is allocating an enumerator. Dictionary has a struct-based enumerator.
  • Every cleanup operation is allocating an array to store the items to be removed (even if there aren't any to be removed). Dictionary supports removal during enumeration, so this can be removed entirely.

Customer Impact

Unnecessary allocations

Regression

No

Testing

CI

Risk

Minimal

Microsoft Reviewers: Open in CodeFlow

Use a strongly-typed Dictionary instead.

- The key is a struct.  Every time an item is added to the table or a lookup into the table is performed, the key is getting boxed. Using Dictionary avoids all this boxing.
- The struct key lacks a strongly-typed Equals.  Every comparison results in a boxing.  Gave the key a strongly-typed Equals.
- Every cleanup operation is allocating an enumerator.  Dictionary has a struct-based enumerator.
- Every cleanup operation is allocating an array to store the items to be removed (even if there aren't any to be removed).  Dictionary supports removal during enumeration, so this can be removed entirely.
@stephentoub stephentoub requested a review from a team as a code owner April 29, 2022 12:44
@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 dipeshmsft, singhashish-wpf and SamBent April 29, 2022 12:44
@dipeshmsft
Copy link
Member

We have taken this PR for the current Community Test Pass. Thanks for the contribution.

@dipeshmsft dipeshmsft merged commit 2ea94a4 into dotnet:main Aug 12, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 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
None yet
Development

Successfully merging this pull request may close these issues.

2 participants