mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
avoid allocations when adding packets to the sent packet history
This commit is contained in:
parent
07412be8a0
commit
fd38fe4a9a
2 changed files with 18 additions and 18 deletions
|
@ -38,7 +38,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
|
|
||||||
getPacket := func(pn protocol.PacketNumber, encLevel protocol.EncryptionLevel) *Packet {
|
getPacket := func(pn protocol.PacketNumber, encLevel protocol.EncryptionLevel) *Packet {
|
||||||
if el, ok := handler.getPacketNumberSpace(encLevel).history.packetMap[pn]; ok {
|
if el, ok := handler.getPacketNumberSpace(encLevel).history.packetMap[pn]; ok {
|
||||||
return &el.Value
|
return el.Value
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,18 @@ import (
|
||||||
|
|
||||||
type sentPacketHistory struct {
|
type sentPacketHistory struct {
|
||||||
rttStats *utils.RTTStats
|
rttStats *utils.RTTStats
|
||||||
outstandingPacketList *list.List[Packet]
|
outstandingPacketList *list.List[*Packet]
|
||||||
etcPacketList *list.List[Packet]
|
etcPacketList *list.List[*Packet]
|
||||||
packetMap map[protocol.PacketNumber]*list.Element[Packet]
|
packetMap map[protocol.PacketNumber]*list.Element[*Packet]
|
||||||
highestSent protocol.PacketNumber
|
highestSent protocol.PacketNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSentPacketHistory(rttStats *utils.RTTStats) *sentPacketHistory {
|
func newSentPacketHistory(rttStats *utils.RTTStats) *sentPacketHistory {
|
||||||
return &sentPacketHistory{
|
return &sentPacketHistory{
|
||||||
rttStats: rttStats,
|
rttStats: rttStats,
|
||||||
outstandingPacketList: list.New[Packet](),
|
outstandingPacketList: list.New[*Packet](),
|
||||||
etcPacketList: list.New[Packet](),
|
etcPacketList: list.New[*Packet](),
|
||||||
packetMap: make(map[protocol.PacketNumber]*list.Element[Packet]),
|
packetMap: make(map[protocol.PacketNumber]*list.Element[*Packet]),
|
||||||
highestSent: protocol.InvalidPacketNumber,
|
highestSent: protocol.InvalidPacketNumber,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func (h *sentPacketHistory) SentPacket(p *Packet, isAckEliciting bool) {
|
||||||
}
|
}
|
||||||
// Skipped packet numbers.
|
// Skipped packet numbers.
|
||||||
for pn := h.highestSent + 1; pn < p.PacketNumber; pn++ {
|
for pn := h.highestSent + 1; pn < p.PacketNumber; pn++ {
|
||||||
el := h.etcPacketList.PushBack(Packet{
|
el := h.etcPacketList.PushBack(&Packet{
|
||||||
PacketNumber: pn,
|
PacketNumber: pn,
|
||||||
EncryptionLevel: p.EncryptionLevel,
|
EncryptionLevel: p.EncryptionLevel,
|
||||||
SendTime: p.SendTime,
|
SendTime: p.SendTime,
|
||||||
|
@ -44,11 +44,11 @@ func (h *sentPacketHistory) SentPacket(p *Packet, isAckEliciting bool) {
|
||||||
h.highestSent = p.PacketNumber
|
h.highestSent = p.PacketNumber
|
||||||
|
|
||||||
if isAckEliciting {
|
if isAckEliciting {
|
||||||
var el *list.Element[Packet]
|
var el *list.Element[*Packet]
|
||||||
if p.outstanding() {
|
if p.outstanding() {
|
||||||
el = h.outstandingPacketList.PushBack(*p)
|
el = h.outstandingPacketList.PushBack(p)
|
||||||
} else {
|
} else {
|
||||||
el = h.etcPacketList.PushBack(*p)
|
el = h.etcPacketList.PushBack(p)
|
||||||
}
|
}
|
||||||
h.packetMap[p.PacketNumber] = el
|
h.packetMap[p.PacketNumber] = el
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func (h *sentPacketHistory) Iterate(cb func(*Packet) (cont bool, err error)) err
|
||||||
cont := true
|
cont := true
|
||||||
outstandingEl := h.outstandingPacketList.Front()
|
outstandingEl := h.outstandingPacketList.Front()
|
||||||
etcEl := h.etcPacketList.Front()
|
etcEl := h.etcPacketList.Front()
|
||||||
var el *list.Element[Packet]
|
var el *list.Element[*Packet]
|
||||||
// whichever has the next packet number is returned first
|
// whichever has the next packet number is returned first
|
||||||
for cont {
|
for cont {
|
||||||
if outstandingEl == nil || (etcEl != nil && etcEl.Value.PacketNumber < outstandingEl.Value.PacketNumber) {
|
if outstandingEl == nil || (etcEl != nil && etcEl.Value.PacketNumber < outstandingEl.Value.PacketNumber) {
|
||||||
|
@ -76,7 +76,7 @@ func (h *sentPacketHistory) Iterate(cb func(*Packet) (cont bool, err error)) err
|
||||||
etcEl = etcEl.Next()
|
etcEl = etcEl.Next()
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
cont, err = cb(&el.Value)
|
cont, err = cb(el.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (h *sentPacketHistory) FirstOutstanding() *Packet {
|
||||||
if el == nil {
|
if el == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &el.Value
|
return el.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *sentPacketHistory) Len() int {
|
func (h *sentPacketHistory) Len() int {
|
||||||
|
@ -114,7 +114,7 @@ func (h *sentPacketHistory) HasOutstandingPackets() bool {
|
||||||
|
|
||||||
func (h *sentPacketHistory) DeleteOldPackets(now time.Time) {
|
func (h *sentPacketHistory) DeleteOldPackets(now time.Time) {
|
||||||
maxAge := 3 * h.rttStats.PTO(false)
|
maxAge := 3 * h.rttStats.PTO(false)
|
||||||
var nextEl *list.Element[Packet]
|
var nextEl *list.Element[*Packet]
|
||||||
// we don't iterate outstandingPacketList, as we should not delete outstanding packets.
|
// we don't iterate outstandingPacketList, as we should not delete outstanding packets.
|
||||||
// being outstanding for more than 3*PTO should only happen in the case of drastic RTT changes.
|
// being outstanding for more than 3*PTO should only happen in the case of drastic RTT changes.
|
||||||
for el := h.etcPacketList.Front(); el != nil; el = nextEl {
|
for el := h.etcPacketList.Front(); el != nil; el = nextEl {
|
||||||
|
@ -145,10 +145,10 @@ func (h *sentPacketHistory) DeclareLost(p *Packet) *Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if el == nil {
|
if el == nil {
|
||||||
el = h.etcPacketList.PushFront(*p)
|
el = h.etcPacketList.PushFront(p)
|
||||||
} else {
|
} else {
|
||||||
el = h.etcPacketList.InsertAfter(*p, el)
|
el = h.etcPacketList.InsertAfter(p, el)
|
||||||
}
|
}
|
||||||
h.packetMap[p.PacketNumber] = el
|
h.packetMap[p.PacketNumber] = el
|
||||||
return &el.Value
|
return el.Value
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue