Skip to content

Avoid duplicate GetHashCode() values in TokenMap#48897

Merged
cston merged 1 commit intodotnet:masterfrom
cston:48886
Oct 25, 2020
Merged

Avoid duplicate GetHashCode() values in TokenMap#48897
cston merged 1 commit intodotnet:masterfrom
cston:48886

Conversation

@cston
Copy link
Contributor

@cston cston commented Oct 24, 2020

TokenMap stores symbols used in code generation in a dictionary mapped to index. The symbols are compared by reference* so, ideally, the hash codes for the symbols should be distinct if the symbols are distinct instances.

Fixes #48886.

In the bug repro, many symbols are added to the map for the same method (a SubstitutedMethodSymbol for an anonymous type constructor). The map was using SubstitutedMethodSymbol.GetHashCode() for those symbols so the dictionary performed poorly (in ConcurrentDictionary<IReferenceOrSignature, uint>.TryAdd(TKey, TValue) in particular) since many items had the same hash code value.

*There is a separate question of whether TokenMap should contain separate entries for multiple instances of the same symbol. I will confirm.

[Thanks to @jaredpar for suggesting hashcode collisions as the issue.]

@cston cston requested a review from a team as a code owner October 24, 2020 05:22
@jcouv
Copy link
Member

jcouv commented Oct 24, 2020

Could you share some details about this being the root of the issue? I'm missing the link. Thanks

@cston
Copy link
Contributor Author

cston commented Oct 24, 2020

@jcouv, I've updated the description with details, thanks.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 1)

@jcouv jcouv self-assigned this Oct 25, 2020
@jaredpar
Copy link
Member

There is a separate question of whether TokenMap should contain separate entries for multiple instances of the same symbol. I will confirm.

That does seem a bit suspicious and contrary to my intuition here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RC2 won't compile large collections of large files

4 participants