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

Replace Values with KeyValuePair enumerator in MemoryCache #53762

Merged
merged 4 commits into from
Jun 10, 2021

Conversation

ezgambac
Copy link
Contributor

@ezgambac ezgambac commented Jun 5, 2021

ConcurrentDictionary.Values will lock all the locks in the MemoryCache internal _entries ConcurrentDictionary .
However, using regular dictionary enumerator which returns a KeyValuePair<TKey, TValue> does not cause locking.
This is important in heavy throughput scenarios as accessing .Values could reduce write throughput for the MemoryCache.

Changed code to use KeyValuePair enumerator
Update MemoryCache to use KeyValuePair enumerator from concurrent dictionary
@ghost
Copy link

ghost commented Jun 5, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan, @michaelgsharp
See info in area-owners.md if you want to be subscribed.

Issue Details

ConcurrentDictionary.Values will lock all the locks in the MemoryCache internal _entries ConcurrentDictionary .
However, using regular dictionary enumerator which returns a KeyValuePair<TKey, TValue> does not cause locking.
This is important in heavy throughput scenarios as accessing .Values could reduce write throughput for the MemoryCache.

Author: ezgambac
Assignees: -
Labels:

area-Extensions-Caching

Milestone: -

@ezgambac
Copy link
Contributor Author

ezgambac commented Jun 7, 2021

Related issue:
#53761

@ezgambac
Copy link
Contributor Author

@martincostello @eerhardt any other comments?

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @ezgambac !

@adamsitnik adamsitnik added this to the 6.0.0 milestone Jun 10, 2021
@adamsitnik adamsitnik merged commit 00ee1c1 into dotnet:main Jun 10, 2021
edevoogd added a commit to edevoogd/runtime that referenced this pull request Jun 21, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants