perf: NodesSnapshot, do not hold m_nodes_mutex while shuffling

This commit is contained in:
pasta 2024-12-09 14:40:36 -06:00
parent 7c00c868d8
commit c005011e84
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -5117,17 +5117,17 @@ bool CConnman::IsMasternodeOrDisconnectRequested(const CService& addr) {
CConnman::NodesSnapshot::NodesSnapshot(const CConnman& connman, std::function<bool(const CNode* pnode)> filter,
bool shuffle)
{
{
LOCK(connman.m_nodes_mutex);
m_nodes_copy.reserve(connman.m_nodes.size());
for (auto& node : connman.m_nodes) {
if (!filter(node))
continue;
if (!filter(node)) continue;
node->AddRef();
m_nodes_copy.push_back(node);
}
}
if (shuffle) {
Shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});
}