Skip to content

Replace Values with KeyValuePair enumerator in MemoryCache - #53762

Merged
adamsitnik merged 4 commits into
dotnet:mainfrom
ezgambac:main
Jun 10, 2021
Merged

adamsitnik merged 4 commits into
dotnet:mainfrom
ezgambac:main

Conversation

@ezgambac

@ezgambac ezgambac commented Jun 5, 2021

Copy link
Copy Markdown
Contributor

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.

ezgambac added 3 commits June 4, 2021 21:50
Changed code to use KeyValuePair enumerator
Update MemoryCache to use KeyValuePair enumerator from concurrent dictionary
@ghost

ghost commented Jun 5, 2021

Copy link
Copy Markdown

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

ezgambac commented Jun 7, 2021

Copy link
Copy Markdown
Contributor Author

Related issue:
#53761

@ezgambac

Copy link
Copy Markdown
Contributor Author

@martincostello @eerhardt any other comments?

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

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