diff --git a/.changelog/unreleased/improvements/2952-lower-next-packet-msg-time.md b/.changelog/unreleased/improvements/2952-lower-next-packet-msg-time.md new file mode 100644 index 00000000000..6a05588c0f6 --- /dev/null +++ b/.changelog/unreleased/improvements/2952-lower-next-packet-msg-time.md @@ -0,0 +1,2 @@ +- `[p2p/conn]` Minor speedup (3%) to connection.WritePacketMsgTo, by removing MinInt calls. + ([\#2952](https://github.com/cometbft/cometbft/pull/2952)) \ No newline at end of file diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index 8ce52f58b8d..e0a471a4606 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -22,7 +22,6 @@ import ( cmtsync "github.com/cometbft/cometbft/internal/sync" "github.com/cometbft/cometbft/internal/timer" "github.com/cometbft/cometbft/libs/log" - cmtmath "github.com/cometbft/cometbft/libs/math" ) const ( @@ -835,14 +834,15 @@ func (ch *Channel) isSendPending() bool { func (ch *Channel) nextPacketMsg() tmp2p.PacketMsg { packet := tmp2p.PacketMsg{ChannelID: int32(ch.desc.ID)} maxSize := ch.maxPacketMsgPayloadSize - packet.Data = ch.sending[:cmtmath.MinInt(maxSize, len(ch.sending))] if len(ch.sending) <= maxSize { + packet.Data = ch.sending packet.EOF = true ch.sending = nil atomic.AddInt32(&ch.sendQueueSize, -1) // decrement sendQueueSize } else { + packet.Data = ch.sending[:maxSize] packet.EOF = false - ch.sending = ch.sending[cmtmath.MinInt(maxSize, len(ch.sending)):] + ch.sending = ch.sending[maxSize:] } return packet }