Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(p2p/conn): Remove a minint call that was appearing in write pack… #42

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[p2p/conn]` Minor speedup (3%) to connection.WritePacketMsgTo, by removing MinInt calls.
([\#2952](https://github.com/cometbft/cometbft/pull/2952))
6 changes: 3 additions & 3 deletions p2p/conn/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
Loading