Reduce descriptor marshal allocations on Go 1.26.4/linux-amd64 (#4681)
* Reduce descriptor marshal allocations on Go 1.26.4/linux-amd64 Signed-off-by: Perfloop Agent <agent@perfloop.ai> * Use require in the descriptor marshal benchmark test Signed-off-by: Perfloop Agent <agent@perfloop.ai> * sfu: marshal dependency descriptors into caller-owned scratch * sfu: reuse the selector's descriptor clone * sfu: share one inline header-extension size constant --------- Signed-off-by: Perfloop Agent <agent@perfloop.ai>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package pacer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"github.com/livekit/protocol/logger"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/bwe"
|
||||
dd "github.com/livekit/livekit-server/pkg/sfu/rtpextension/dependencydescriptor"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/utils"
|
||||
)
|
||||
|
||||
@@ -85,3 +87,23 @@ func TestSendPacketHeaderExtensionsNoAlloc(t *testing.T) {
|
||||
require.Equal(t, 0.0, allocs, "allocations per SendPacket")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHoldExtension(t *testing.T) {
|
||||
p := &Packet{}
|
||||
|
||||
ext := []byte{1, 2, 3}
|
||||
held := p.HoldExtension(ext)
|
||||
require.Equal(t, ext, held)
|
||||
require.Same(t, &p.extBuf[0], &held[0], "the extension has to be held in the packet's scratch")
|
||||
|
||||
ext[0] = 9
|
||||
require.EqualValues(t, 1, held[0], "the held copy has to be independent of the caller's slice")
|
||||
|
||||
// exactly the one byte extension profile payload cap
|
||||
exact := bytes.Repeat([]byte{7}, dd.MaxInlineExtensionSize)
|
||||
held = p.HoldExtension(exact)
|
||||
require.Equal(t, exact, held)
|
||||
|
||||
// one byte more does not fit
|
||||
require.Nil(t, p.HoldExtension(bytes.Repeat([]byte{7}, dd.MaxInlineExtensionSize+1)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user