From de6f4987f6418d7a5fe9026573797e83eaefea7f Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 6 Aug 2021 13:32:43 +0300 Subject: [PATCH] network: microoptimize iteratePeersWithSendMsg() Now that s.getPeers() returns a slice we can use slice for `success` too, maps are more expensive. --- pkg/network/server.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 0eb6e2a77..a4311a521 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -1154,12 +1154,11 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, bool, []b return } - success := make(map[Peer]bool, len(peers)) + success := make([]bool, len(peers)) okCount := 0 sentCount := 0 - for _, peer := range peers { + for i, peer := range peers { if peerOK != nil && !peerOK(peer) { - success[peer] = false continue } okCount++ @@ -1169,7 +1168,7 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, bool, []b if msg.Command == CMDGetAddr { peer.AddGetAddrSent() } - success[peer] = true + success[i] = true sentCount++ } @@ -1179,8 +1178,8 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, bool, []b } // Perform blocking send now. - for _, peer := range peers { - if _, ok := success[peer]; ok || peerOK != nil && !peerOK(peer) { + for i, peer := range peers { + if success[i] || (peerOK != nil && !peerOK(peer)) { continue } if err := send(peer, true, pkt); err != nil {