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 1a776c73c53..0407b9e9b9c 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -16,7 +16,6 @@ import ( flow "github.com/cometbft/cometbft/libs/flowrate" "github.com/cometbft/cometbft/libs/log" - cmtmath "github.com/cometbft/cometbft/libs/math" "github.com/cometbft/cometbft/libs/protoio" "github.com/cometbft/cometbft/libs/service" cmtsync "github.com/cometbft/cometbft/libs/sync" @@ -830,14 +829,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 }