From c005011e841c0ce2220b3a4283e8dff00707b465 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 45ebdafbf9..de19086d18 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{}); }