Use sync.Pool for objects in packet path. (#4066)

* Use sync.Pool for objects in packet path.

Seeing cases of forwarding latency spikes that aling with GC.

This might be a bit overkill, but using sync.Pool for small +
short-lived objects in packet path.

Before this, all these were increasing in alloc_space heap profile
samples over time. With these, there is no increase (actually the lines
corresponding to geting from pool does not even show up in heap
accounting when doing `list` in `pprof`)

* merge

* Paul feedback
This commit is contained in:
Raja Subramanian
2025-11-14 16:13:23 +05:30
committed by GitHub
parent f8b994d491
commit c3964ba2eb
8 changed files with 125 additions and 30 deletions
+11
View File
@@ -23,6 +23,16 @@ import (
"github.com/pion/webrtc/v4"
)
var (
PacketFactory = &sync.Pool{
New: func() any {
return &Packet{}
},
}
)
// --------------------------------------
type PacerBehavior string
const (
@@ -33,6 +43,7 @@ const (
type Packet struct {
Header *rtp.Header
HeaderPool *sync.Pool
HeaderSize int
Payload []byte
IsRTX bool