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

MECM MemoryCache performance; split string keys into separate collection #111502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mgravell
Copy link
Member

@mgravell mgravell commented Jan 16, 2025

Historically, MECM MemoryCache uses a single lookup of object types. The runtime includes advanced key re-hashing in the relevant dictionary types, but this is restricted to TKey === typeof(string), which won't apply. We resolve this by splitting the collection into two - one for string keys, one for everything else. This allows the string keys (which is most of them, in many cases) to be re-hashed automatically. This improves performance in catastrophic key collision scenarios.

MECM is an OOB NuGet package with net462 and netstandard2.0 targets (in addition to up-level). On down-level TFMs, where this re-hashing isn't available, we can still mitigate against the impact of this by using Marvin; this means that collision scenarios are different per execution, reducing risk by repeatable scenarios.

Changes:

  • split string and non-string keys into separate collections, to allow re-hashing of string keys
  • use Marvin explicitly on down-level TFMs (it is implicit on up-level)

Note:

- split string and non-string keys into separate collections, to
  allow re-hashing of string keys
- use Marvin explicitly on down-level TFMs (it is implicit on up-level)
Copy link
Contributor

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

@mgravell
Copy link
Member Author

mgravell commented Jan 17, 2025

/cc @adamsitnik as a reviewer of the original net9 PR (42427)

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.

1 participant