on main help sign in
fix(pubsub): raise default per-subscriber buffer (64 -> 4096)
0585f49Sven Olsen
internal/pubsub/broker.go+7−5
@@ -5,26 +5,28 @@ import (
5 "sync"
5 "sync"
6)
6)
7
7
8+// bufferSize is the per-subscriber channel capacity for any broker
9+// created via NewBroker. Publish is non-blocking, so a full buffer
10+// silently drops events; sized to cover a long streaming assistant
11+// turn (~one UpdatedEvent per token) even under TUI render stalls.
8−const bufferSize = 64
12+const bufferSize = 4096
9
13
10type Broker[T any] struct {
14type Broker[T any] struct {
11 subs map[chan Event[T]]struct{}
15 subs map[chan Event[T]]struct{}
12 mu sync.RWMutex
16 mu sync.RWMutex
13 done chan struct{}
17 done chan struct{}
14 subCount int
18 subCount int
15− maxEvents int
16 channelBufferSize int
19 channelBufferSize int
17}
20}
18
21
19func NewBroker[T any]() *Broker[T] {
22func NewBroker[T any]() *Broker[T] {
20− return NewBrokerWithOptions[T](bufferSize, 1000)
23+ return NewBrokerWithOptions[T](bufferSize)
21}
24}
22
25
23−func NewBrokerWithOptions[T any](channelBufferSize, maxEvents int) *Broker[T] {
26+func NewBrokerWithOptions[T any](channelBufferSize int) *Broker[T] {
24 return &Broker[T]{
27 return &Broker[T]{
25 subs: make(map[chan Event[T]]struct{}),
28 subs: make(map[chan Event[T]]struct{}),
26 done: make(chan struct{}),
29 done: make(chan struct{}),
27− maxEvents: maxEvents,
28 channelBufferSize: channelBufferSize,
30 channelBufferSize: channelBufferSize,
29 }
31 }
30}
32}