diff --git a/gossipsub.go b/gossipsub.go index 117b585c..dcc5d193 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -19,6 +19,8 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-libp2p/core/record" "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" + + "go.uber.org/zap/zapcore" ) const ( @@ -1334,7 +1336,9 @@ func (gs *GossipSubRouter) sendRPC(p peer.ID, out *RPC, urgent bool) { } func (gs *GossipSubRouter) doDropRPC(rpc *RPC, p peer.ID, reason string) { - log.Debugf("dropping message to peer %s: %s", p, reason) + if log.Level() <= zapcore.DebugLevel { + log.Debugf("dropping message to peer %s: %s", p, reason) + } gs.tracer.DropRPC(rpc, p) // push control messages that need to be retried ctl := rpc.GetControl() diff --git a/gossipsub_test.go b/gossipsub_test.go index 3b45557c..d515654f 100644 --- a/gossipsub_test.go +++ b/gossipsub_test.go @@ -3175,3 +3175,11 @@ func TestGossipsubIdontwantClear(t *testing.T) { <-ctx.Done() } + +func BenchmarkAllocDoDropRPC(b *testing.B) { + gs := GossipSubRouter{tracer: &pubsubTracer{}} + + for i := 0; i < b.N; i++ { + gs.doDropRPC(&RPC{}, "peerID", "reason") + } +}