From f486808fbed1d7b36cd05029ec76876c52d718d9 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sun, 23 Feb 2025 17:39:38 -0500 Subject: [PATCH] feat: avoid repeated checksum calculations (#599) We don't need to recalculate the checksum for each peer. --- gossipsub.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gossipsub.go b/gossipsub.go index 56b6886..214696b 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -1196,11 +1196,11 @@ func (gs *GossipSubRouter) Publish(msg *Message) { gs.lastpub[topic] = time.Now().UnixNano() } + csum := computeChecksum(gs.p.idGen.ID(msg)) for p := range gmap { - mid := gs.p.idGen.ID(msg) // Check if it has already received an IDONTWANT for the message. // If so, don't send it to the peer - if _, ok := gs.unwanted[p][computeChecksum(mid)]; ok { + if _, ok := gs.unwanted[p][csum]; ok { continue } tosend[p] = struct{}{}