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

Remove ConcurrentDictionary from RelationalTransactionRegistry #279

Merged
merged 5 commits into from
Apr 24, 2024

Conversation

YuKitsune
Copy link
Contributor

@YuKitsune YuKitsune commented Feb 12, 2024

[sc-67483]

@YuKitsune YuKitsune changed the title Remove ConcurrentDictionary from RelationalTransactionRegistry Spike: Remove ConcurrentDictionary from RelationalTransactionRegistry Feb 12, 2024
Copy link

@borland borland marked this pull request as ready for review March 4, 2024 03:52
@borland borland requested a review from a team as a code owner March 4, 2024 03:52
@borland borland changed the title Spike: Remove ConcurrentDictionary from RelationalTransactionRegistry Remove ConcurrentDictionary from RelationalTransactionRegistry Mar 4, 2024
@borland
Copy link
Contributor

borland commented Mar 4, 2024

Adam and I jumped on this and tweaked it to use a List instead of Dictionary, as it never looked up anything by the dictionary keys anyway.

Ad-hoc BenchmarkDotnet results

baseline on master:

|                       Method |     Mean |   Error |  StdDev |
|----------------------------- |---------:|--------:|--------:|
| AddTransactionWithoutLogging | 154.6 ms | 2.84 ms | 4.82 ms |

Code in this PR:

|                       Method |     Mean |     Error |    StdDev |   Median |
|----------------------------- |---------:|----------:|----------:|---------:|
| AddTransactionWithoutLogging | 6.444 ms | 0.1285 ms | 0.3003 ms | 6.295 ms |

Copy link
Contributor

@rosslovas rosslovas left a comment

Choose a reason for hiding this comment

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

Adam and I jumped on this and tweaked it to use a List instead of Dictionary, as it never looked up anything by the dictionary keys anyway.

This is not true, it looks up by the key on Remove. This has changed from a hash lookup to a linear scan. Blocking to discuss

@adam-mccoy
Copy link
Contributor

I've added some benchmarks and tested using a few collection types. Below are the results.

5,000 transaction ("Realistic") 100,000 transactions ("Extreme")
ConcurrentDictionary Add 53.45ms 1280.43ms
Remove 0.127ms 5.806ms
List Add 0.869ms 43.681ms
Remove 1.098ms 519.403ms
HashSet Add 1.307ms 81.638ms
Remove 0.124ms 3.529ms
  • The difference between List<T> and HashSet<T> at a "realistic" transaction count (5,000) is insignificant
  • Both allow adding much more quickly than ConcurrentDictionary<TKey, TValue>
  • With a very large count, HashSet<T> performs significantly better (~175x) with removals, while only performing slightly worse (~2x) on adds

Based on the above findings, I've gone with HashSet<T>. While I don't think the decision is going to make a noticeable difference in almost all cases, the potential performance trade-off is more favourable with HashSet<T>.

@rosslovas could you please take a look at the above and let me know if you agree?

@borland
Copy link
Contributor

borland commented Apr 23, 2024

I've looked at the code+benchmarks and run them locally as well, I get similar results to Adam. I think we should merge the HashSet change in

Copy link
Contributor

@rosslovas rosslovas left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, didn't get a notification for your last comment. LGTM!

@adam-mccoy adam-mccoy merged commit e1efc75 into master Apr 24, 2024
3 checks passed
@adam-mccoy adam-mccoy deleted the eoin/pet/mqs/concurrent-dictionary branch April 24, 2024 04:52
@borland
Copy link
Contributor

borland commented Apr 26, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants