sfu: patch pacer header extensions without per-packet allocation (#4872)

SendPacket allocated four times per down track write: a 3 byte slice for
abs-send-time, a 2 byte slice for transport-cc, and two appends to a nil
Extensions slice because the pooled header was reset to a zero value.

Give pacer.Packet fixed scratch arrays for the two extensions and marshal
into them. The Packet is pooled and owned by one send until SendPacket
returns, so nothing is shared across down tracks. Keep the pooled header's
Extensions capacity across reuse, both when returning it to the pool and
when a down track initializes it.

Adds a test that asserts zero allocations per SendPacket.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Raja Subramanian
2026-09-15 21:48:24 +05:30
committed by GitHub
co-authored by Claude Fable 5.1
parent 0392ca90b4
commit 61a31d31ff
5 changed files with 112 additions and 14 deletions
+5
View File
@@ -54,6 +54,11 @@ type Packet struct {
WriteStream webrtc.TrackLocalWriter
Pool *sync.Pool
PoolEntity *[]byte
// per-packet scratch for header extensions patched at send time,
// the Packet is owned by one send until SendPacket returns
absSendTimeBuf [3]byte
twccBuf [2]byte
}
type Pacer interface {