-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use a sync.Pool to avoid allocations of ackhandler.Packet
- Loading branch information
1 parent
fd38fe4
commit 3207222
Showing
4 changed files
with
63 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ackhandler | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/lucas-clemente/quic-go/internal/protocol" | ||
) | ||
|
||
// A Packet is a packet | ||
type Packet struct { | ||
PacketNumber protocol.PacketNumber | ||
Frames []Frame | ||
LargestAcked protocol.PacketNumber // InvalidPacketNumber if the packet doesn't contain an ACK | ||
Length protocol.ByteCount | ||
EncryptionLevel protocol.EncryptionLevel | ||
SendTime time.Time | ||
|
||
IsPathMTUProbePacket bool // We don't report the loss of Path MTU probe packets to the congestion controller. | ||
|
||
includedInBytesInFlight bool | ||
declaredLost bool | ||
skippedPacket bool | ||
} | ||
|
||
func (p *Packet) outstanding() bool { | ||
return !p.declaredLost && !p.skippedPacket && !p.IsPathMTUProbePacket | ||
} | ||
|
||
var packetPool = sync.Pool{New: func() any { return &Packet{} }} | ||
|
||
func GetPacket() *Packet { | ||
p := packetPool.Get().(*Packet) | ||
p.PacketNumber = 0 | ||
p.Frames = nil | ||
p.LargestAcked = 0 | ||
p.Length = 0 | ||
p.EncryptionLevel = protocol.EncryptionLevel(0) | ||
p.SendTime = time.Time{} | ||
p.IsPathMTUProbePacket = false | ||
p.includedInBytesInFlight = false | ||
p.declaredLost = false | ||
p.skippedPacket = false | ||
return p | ||
} | ||
|
||
// We currently only return Packets back into the pool when they're acknowledged (not when they're lost). | ||
// This simplifies the code, and gives the vast majority of the performance benefit we can gain from using the pool. | ||
func putPacket(p *Packet) { packetPool.Put(p) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters