forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge dashpay#6497: perf: use unordered_set / unordered_map where ord…
…er isn't relevant a04d178 perf: use unordered_set / unordered_map where order isn't relevant (pasta) Pull request description: ## Issue being fixed or feature implemented We use std::set and std::map where we do not care about order, and it's mostly serves as a lookup. I couldn't find any instances in the code where we actually care about the ordering of these sets or maps. In this case, we should probably prefer using unordered_set and unordered_map. ## What was done? Converted these sets / maps into their unordered equivalent . ## How Has This Been Tested? Did a few quickbench to ensure there isn't some significant advantage to using the "worse" data structure at small sizes. these used sizes up to around 1000 instances per map / set, as this is the max number of connects we are every likely to see. set: https://quick-bench.com/q/ApPAGguzG2F9AnqM2GkgDAXCzX4 map: https://quick-bench.com/q/PXDdF0HVGpiSmC9Hh5FUSTp0uJU In this we see there is never a reason to use set over unordered_set, assuming that order isn't important. Using unordered_map did show a small insertion regression for ~expected sizes on masternodes, but it appears that only 1 lookup will compensate for that overhead, and based on the codepaths, I expect more than 1 lookup per insertion. some perf results I have are here, show that this std::set usage is causing at least a measurable cpu usage. ``` - 9.18% 0.00% d-mncon dashd [.] CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager&, CMasternodeMetaMan&, CMasternodeSync&)::{lambda()#▒ - CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager&, CMasternodeMetaMan&, CMasternodeSync&)::{lambda()#1}::operator()() const ▒ + 6.16% CConnman::IsMasternodeOrDisconnectRequested(CService const&) ▒ - 2.66% std::set<CService, std::less<CService>, std::allocator<CService> >::count(CService const&) const ▒ - std::_Rb_tree<CService, CService, std::_Identity<CService>, std::less<CService>, std::allocator<CService> >::find(CService const&) const ▒ - 2.02% std::_Rb_tree<CService, CService, std::_Identity<CService>, std::less<CService>, std::allocator<CService> >::_M_lower_bound(std::_Rb_tree_node<CService> const▒ + 1.99% std::less<CService>::operator()(CService const&, CService const&) const ▒ + 0.62% std::less<CService>::operator()(CService const&, CService const&) const ``` ## Breaking Changes None ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK a04d178 knst: utACK a04d178 Tree-SHA512: 18a11d5ec55a0a96e4fa41694e11de628b84a7819112eae47591803aa0a8729bde38f8b9d93c91a52d3be481d68d1be7e03e130932c4480210e98cd35825a018
- Loading branch information
Showing
7 changed files
with
47 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters