From 8098d9d209f397fa644ad52863f25cacce80ed8f Mon Sep 17 00:00:00 2001 From: pasta Date: Mon, 9 Dec 2024 14:40:36 -0600 Subject: [PATCH] perf: NodesSnapshot, do not hold m_nodes_mutex while shuffling --- src/net.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 45ebdafbf98f7f..de19086d18b522 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -5118,16 +5118,16 @@ bool CConnman::IsMasternodeOrDisconnectRequested(const CService& addr) { CConnman::NodesSnapshot::NodesSnapshot(const CConnman& connman, std::function filter, bool shuffle) { - LOCK(connman.m_nodes_mutex); - m_nodes_copy.reserve(connman.m_nodes.size()); + { + LOCK(connman.m_nodes_mutex); + m_nodes_copy.reserve(connman.m_nodes.size()); - for (auto& node : connman.m_nodes) { - if (!filter(node)) - continue; - node->AddRef(); - m_nodes_copy.push_back(node); + for (auto& node : connman.m_nodes) { + if (!filter(node)) continue; + node->AddRef(); + m_nodes_copy.push_back(node); + } } - if (shuffle) { Shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{}); }