batch: move shared-arena Reset ownership from lanes to their owner

This commit is contained in:
JackDoan
2026-07-14 11:51:32 -05:00
parent 05f7923860
commit 97eb3c635a
9 changed files with 163 additions and 90 deletions
+21 -11
View File
@@ -8,11 +8,11 @@ import (
// Passthrough is a RxBatcher that doesn't batch anything, it just accumulates and then sends packets.
type Passthrough struct {
out io.Writer
slots [][]byte
// arena is injected; see TCPCoalescer.arena for the contract.
arena *Arena
cursor int
out io.Writer
slots [][]byte
reserver Reserver
resetter Resetter
cursor int
}
const passthroughBaseNumSlots = 128
@@ -21,16 +21,17 @@ const passthroughBaseNumSlots = 128
// standalone Passthrough batcher: 128 slots × udp.MTU ≈ 1.1 MiB.
const DefaultPassthroughArenaCap = passthroughBaseNumSlots * udp.MTU
func NewPassthrough(w io.Writer, arena *Arena) *Passthrough {
func NewPassthrough(w io.Writer, reserver Reserver, resetter Resetter) *Passthrough {
return &Passthrough{
out: w,
slots: make([][]byte, 0, passthroughBaseNumSlots),
arena: arena,
out: w,
slots: make([][]byte, 0, passthroughBaseNumSlots),
reserver: reserver,
resetter: resetter,
}
}
func (p *Passthrough) Reserve(sz int) []byte {
return p.arena.Reserve(sz)
return p.reserver(sz)
}
func (p *Passthrough) Commit(pkt []byte) error {
@@ -38,7 +39,17 @@ func (p *Passthrough) Commit(pkt []byte) error {
return nil
}
// Flush drains every queued packet and calls the configured Resetter
func (p *Passthrough) Flush() error {
firstErr := p.drain()
if p.resetter != nil {
p.resetter()
}
return firstErr
}
// drain writes out every queued packet and clears the slot list.
func (p *Passthrough) drain() error {
var firstErr error
for _, s := range p.slots {
_, err := p.out.Write(s)
@@ -48,6 +59,5 @@ func (p *Passthrough) Flush() error {
}
clear(p.slots)
p.slots = p.slots[:0]
p.arena.Reset()
return firstErr
}