-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Allow custom equality comparer on ConcurrentDictionary TryUpdate #25559
Comments
I've rebased my PR and ran the tests xUnit.net console test runner (64-bit .NET Core)
Copyright (C) 2014 Outercurve Foundation.
Discovering: System.Collections.Concurrent.Tests
Discovered: System.Collections.Concurrent.Tests
Starting: System.Collections.Concurrent.Tests
Finished: System.Collections.Concurrent.Tests
=== TEST EXECUTION SUMMARY ===
System.Collections.Concurrent.Tests Total: 2079, Errors: 0, Failed: 0, Skipped: 0, Time: 16,444s
----- end 13:53:48,81 ----- exit code 0 ---------------------------------------------------------- |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of the experimental issue cleanup initiative we are currently trialing in a limited number of areas. Please share any feedback you might have in the linked issue. |
I think that this issue is still relevant |
Hi @skarllot, and apologies for the delayed response. Doesn't passing the equality comparer at the constructor level address your use case? I don't believe passing a custom equality comparer on a per-operation basis is practical or a good idea since:
In light of the above, I would not supporting adding such a feature to ConcurrentDictionary. |
Hello @eiriktsarpalis, the issue is that the |
My apologies, I misunderstood your request as exposing a key equality comparer parameter. On quick inspection, it seems that the ConcurrentDictionary implementation is hardcoding You mention performance as a motivating factor for this request. Could you share any benchmarks showing performance improvements of your prototype? I should point out that since dotnet/coreclr#14125 the JIT will devirtualize EqualityComparer.Default.Equals calls so there might be an opportunity to slightly improve performance specifically in the TryUpdateInternal implementation. cc @stephentoub |
I've mention performance because I could compare instances based on version number instead of all members values. |
I suspect that this proposal might cover your use case. |
This issue has been marked with the When ready to submit an amended proposal, please ensure that the original post in this issue has been updated, following the API proposal template and examples as provided in the guidelines. |
The method
TryUpdate
fromConcurrentDictionary
should allow to set a custom equality comparer for the value.Rationale and Usage
A custom equality comparer for
TryUpdate
can target three problems.Ahead Of Time
On some platforms is demanded static compilation ahead of time. On those platforms code generation is not allowed.
When the method
TryUpdate
useEqualityComparer<T>.Default
for value type comparison, it attempts to use Reflection to instantiate a new type which implements theIEqualityComparer<T>
interface. That operation is not allowed on AOT compiled code.Performance
Currently the method
TryUpdate
uses the equality comparer instance fromEqualityComparer<T>.Default
which not be the most optimized comparison for the case.Custom comparison
For external types not controlled by the user that does not implement the intended comparison it is needed to create a wrapper to overcome the lack of a proper comparison.
The same is true if a qualified comparison is needed for specific
TryUpdate
call.Usage
Given those types:
Can be used as:
Proposed API
Pull Request
A PR with the proposed changes is available: dotnet/corefx#28142
The text was updated successfully, but these errors were encountered: