Skip to content

Add more prime sizes to HashMap #117108

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

Merged
merged 2 commits into from
Jun 28, 2025
Merged

Add more prime sizes to HashMap #117108

merged 2 commits into from
Jun 28, 2025

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Jun 27, 2025

We have seen cases where the current sizes are not sufficient and end up with pathological behavior.

We have seen cases where the current sizes are not sufficient and end up
with pathological behavior.
@Copilot Copilot AI review requested due to automatic review settings June 27, 2025 23:04
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 27, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the list of prime numbers used by the hash table to address potential performance issues when the current sizes are insufficient.

  • Added additional larger primes to support cases where the hash table may require more buckets.
  • Enhanced the available prime range for better distribution in high-load scenarios.
Comments suppressed due to low confidence (1)

src/coreclr/vm/hash.cpp:33

  • Consider adding unit tests to verify that the new extended prime list maintains the expected hash table performance under high load scenarios.
4999559, 5999471, 7199369, 8639249, 10367101, 12440521, 14928637, 17914367,

@jkotas jkotas removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 27, 2025
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@jkotas jkotas requested a review from davidwrighton June 27, 2025 23:05
@mangod9
Copy link
Member

mangod9 commented Jun 27, 2025

is there a specific benchmark this will improve?

@jkotas
Copy link
Member Author

jkotas commented Jun 28, 2025

is there a specific benchmark this will improve?

I have cced you on the internal email thread. The 7M limit was hit on .NET 8 by a workload that kept creating marshalled delegates on 50 worker threads and the finalizer thread fell behind cleaning them up. Once the 7M limit was hit, it went downhill even more rapidly due this hashtable behaving pathologically.

Marshalled delegates do not use this hashtable in .NET 10 anymore. This change is to avoid pathological behaviors in case there are other scenario that can store more than 7M elements in the runtime hashtables.

@jkotas
Copy link
Member Author

jkotas commented Jun 28, 2025

/ba-g test failure without a log

@jkotas jkotas merged commit 01b4233 into dotnet:main Jun 28, 2025
96 of 99 checks passed
@jkotas jkotas deleted the more-primes branch June 28, 2025 11:47
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