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:
Perfloop Agent
2026-09-30 23:11:49 +08:00
committed by GitHub
parent 2fab31691b
commit 7ef0cd014e
11 changed files with 490 additions and 43 deletions
@@ -33,23 +33,28 @@ type DependencyDescriptorWriter struct {
descriptor *DependencyDescriptor
structure *FrameDependencyStructure
activeChains uint32
writer *BitStreamWriter
writer BitStreamWriter
bestTemplate TemplateMatch
}
func NewDependencyDescriptorWriter(buf []byte, structure *FrameDependencyStructure, activeChains uint32, descriptor *DependencyDescriptor) (*DependencyDescriptorWriter, error) {
writer := NewBitStreamWriter(buf)
w := &DependencyDescriptorWriter{
func newDependencyDescriptorWriter(buf []byte, structure *FrameDependencyStructure, activeChains uint32, descriptor *DependencyDescriptor) DependencyDescriptorWriter {
return DependencyDescriptorWriter{
descriptor: descriptor,
structure: structure,
activeChains: activeChains,
writer: writer,
writer: BitStreamWriter{buf: buf},
}
return w, w.findBestTemplate()
}
func (w *DependencyDescriptorWriter) ResetBuf(buf []byte) {
w.writer = NewBitStreamWriter(buf)
func NewDependencyDescriptorWriter(buf []byte, structure *FrameDependencyStructure, activeChains uint32, descriptor *DependencyDescriptor) (*DependencyDescriptorWriter, error) {
w := newDependencyDescriptorWriter(buf, structure, activeChains, descriptor)
return &w, w.findBestTemplate()
}
// withBuf returns a copy of the writer that writes into buf, value receiver so a caller owned buffer does not escape
func (w DependencyDescriptorWriter) withBuf(buf []byte) DependencyDescriptorWriter {
w.writer = BitStreamWriter{buf: buf}
return w
}
func (w *DependencyDescriptorWriter) Write() error {