Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Jan 22, 2026

Backport of #123502 to release/10.0

/cc @AaronRobinsonMSFT @copilot

Customer Impact

  • Customer reported
  • Found internally

When large numbers of TypeMapAssociationAttribute exist, it can occur that collisions of type names (strings) occur. The current approach ignored the possibility of collision and simply acquired the result of GetHashCode() and inserted that as a key into a Dictionary<,>. This meant there was no opportunity to handle the case when two non-equal string instances generate the same hash code. Using the hash code directly was done to avoid the non-trivial increase in memory usage imposed by using the string instances as the key.

The solution is to use the string as the key instead.

Regression

  • Yes
  • No

Testing

Verified using a CsWinRT repro case. Prior to this fix a collision would occur 1 / 100 times run. After this change the repro ran for more than 1000 iterations with no collisions.

Risk

Low. This new approach does increase the baseline amount of memory when the TypeMap is used on coreclr. This was deemed acceptable since the coreclr isn't considered the P1 scenario for TypeMap. The native AOT, the P1 scenario for TypeMap, is not impacted by this change.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@JulieLeeMSFT JulieLeeMSFT left a comment

Choose a reason for hiding this comment

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

LGTM.

@AaronRobinsonMSFT AaronRobinsonMSFT added Servicing-consider Issue for next servicing release review Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jan 23, 2026
@AaronRobinsonMSFT
Copy link
Member

Approved over email

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.

4 participants