-
Notifications
You must be signed in to change notification settings - Fork 1.2k
perf: do linear lookup instead building 2 heavy Hash-Maps #7176
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ | |
| #include <qt/masternodemodel.h> | ||
| #include <qt/networkwidget.h> | ||
| #include <qt/peertablesortproxy.h> | ||
| #include <qt/util.h> | ||
| #include <qt/walletcontroller.h> | ||
| #include <qt/walletmodel.h> | ||
|
|
||
|
|
@@ -1291,12 +1290,12 @@ void RPCConsole::updateDetailWidget() | |
| } | ||
| ui->peerMappedAS->setText(stats->nodeStats.m_mapped_as != 0 ? QString::number(stats->nodeStats.m_mapped_as) : ts.na); | ||
|
|
||
| const auto addr_key{util::make_array(stats->nodeStats.addr.GetKey())}; | ||
| const MasternodeEntry* dmn = [&]() -> const MasternodeEntry* { | ||
| const auto addr_key{GUIUtil::MakeQByteArray(stats->nodeStats.addr.GetKey())}; | ||
| const std::shared_ptr<MasternodeEntry> dmn = [&]() -> const std::shared_ptr<MasternodeEntry> { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (m_feed_masternode) { | ||
| if (const auto data{m_feed_masternode->data()}; data) { | ||
| if (auto it = data->m_by_service.find(addr_key); it != data->m_by_service.end()) { | ||
| return it.value(); | ||
| for (const auto& mn : data->m_entries) { | ||
| if (mn->serviceKey() == addr_key) return mn; | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: dashpay/dash
Length of output: 489
🏁 Script executed:
rg -n -A5 'struct MasternodeData' srcRepository: dashpay/dash
Length of output: 694
🏁 Script executed:
rg -n 'MasternodeData\s*[({]' src --type=cpp --type=cc --type=h --type=hppRepository: dashpay/dash
Length of output: 82
🏁 Script executed:
rg -n 'interfaces::MnList::Counts' src --type=cpp --type=cc --type=h --type=hpp -B2 -A2Repository: dashpay/dash
Length of output: 82
🏁 Script executed:
Repository: dashpay/dash
Length of output: 3045
🏁 Script executed:
Repository: dashpay/dash
Length of output: 286
🏁 Script executed:
rg -n 'namespace.*MnList\|struct.*Counts\|class.*Counts' src --type=cpp --type=h -A3Repository: dashpay/dash
Length of output: 38
🏁 Script executed:
Repository: dashpay/dash
Length of output: 158
🏁 Script executed:
rg 'struct Counts|class Counts' src --type=cpp --type=h -A10Repository: dashpay/dash
Length of output: 4075
🏁 Script executed:
rg 'MnList::Counts' src --type=cpp --type=h -B3 -A3Repository: dashpay/dash
Length of output: 383
🏁 Script executed:
rg -n 'm_counts' src/qt --type=cpp --type=h -B2 -A2Repository: dashpay/dash
Length of output: 3934
🏁 Script executed:
Repository: dashpay/dash
Length of output: 1095
🏁 Script executed:
Repository: dashpay/dash
Length of output: 38
🏁 Script executed:
Repository: dashpay/dash
Length of output: 38
🏁 Script executed:
rg -n 'struct Counts' src/interfaces/node.h -A12Repository: dashpay/dash
Length of output: 576
Add initializer for consistency with similar structures in the same file.
Line 154 omits the
{}initializer onm_counts. While theinterfaces::MnList::Countstype safely zero-initializes all its members (defined insrc/interfaces/node.h), other similar data structures insrc/qt/clientfeeds.h(CreditPoolDataat line 117 andInstantSendDataat line 135) explicitly initialize theirm_countsmembers with{}. For consistency and clarity:Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's intentionally removed.
interfaces::MnList::Countsis a struct and have default initialized members.{}is not needed here. Moreover it's missleading initialization that makes code reader to assume that initialization by{}is required.Quite contradicately,
m_countsis almost the only member that initialized by this way.For reference, the latest merged PR to bitcoin:
bitcoin@d907d65
There's no enforced call of default constructor. It's default constructor.
More examples class
BlockManager(randomly chosen to show a point):As you can see, trivial POD members, such as
bool,inthave initialized; any struct or class - do not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@knst, thank you for the detailed explanation! You're absolutely right—I appreciate the clarification on the coding convention. The distinction between explicitly initializing POD types (likeboolandint) versus letting struct/class types use their default constructors makes sense and aligns with Bitcoin Core's style.Your point about
{}being potentially misleading is well taken—it can indeed suggest that explicit initialization is required when the default constructor already handles it properly. I'll keep this pattern in mind for future reviews.✏️ Learnings added
🧠 Learnings used