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:
+10
-7
@@ -16,18 +16,21 @@ package sfu
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
var (
|
||||
PacketFactory *sync.Pool
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Init packet factory
|
||||
PacketFactory = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
New: func() any {
|
||||
b := make([]byte, 1460)
|
||||
return &b
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
RTPHeaderFactory = &sync.Pool{
|
||||
New: func() any {
|
||||
return &rtp.Header{}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user