ackhandler: avoid storing packet number in packet struct (#5312)

* ackhandler: optimize memory layout of packet struct

The packet number can be derived from the position that this packet is
stored at in the packets slice in the sent packet history. There is no
need to store the packet number, saving 8 bytes per packet.

* ackhandler: avoid copying the packet struct
This commit is contained in:
Marten Seemann
2025-08-29 10:18:45 +08:00
committed by GitHub
parent 13a9a650f2
commit 5bb2146b47
8 changed files with 218 additions and 175 deletions

View File

@@ -7,10 +7,14 @@ import (
"github.com/quic-go/quic-go/internal/protocol"
)
type packetWithPacketNumber struct {
PacketNumber protocol.PacketNumber
*packet
}
// A Packet is a packet
type packet struct {
SendTime time.Time
PacketNumber protocol.PacketNumber
StreamFrames []StreamFrame
Frames []Frame
LargestAcked protocol.PacketNumber // InvalidPacketNumber if the packet doesn't contain an ACK
@@ -33,7 +37,6 @@ var packetPool = sync.Pool{New: func() any { return &packet{} }}
func getPacket() *packet {
p := packetPool.Get().(*packet)
p.PacketNumber = 0
p.StreamFrames = nil
p.Frames = nil
p.LargestAcked = 0