From 9dec51cd4046354d1e374f6491147aec2dc5d5ed Mon Sep 17 00:00:00 2001 From: mleku Date: Sun, 7 Sep 2025 23:06:46 +0100 Subject: [PATCH] Switch `sync.Mutex` to `sync.RWMutex` in `publisher` for improved concurrent read performance. --- app/publisher.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/publisher.go b/app/publisher.go index 31677e4..1845cc1 100644 --- a/app/publisher.go +++ b/app/publisher.go @@ -56,7 +56,7 @@ func (w *W) Type() (typeName string) { return Type } type P struct { c context.Context // Mx is the mutex for the Map. - Mx sync.Mutex + Mx sync.RWMutex // Map is the map of subscribers and subscriptions from the websocket api. Map } @@ -150,8 +150,8 @@ func (p *P) Receive(msg typer.T) { // for unauthenticated users when events are privileged. func (p *P) Deliver(ev *event.E) { var err error - p.Mx.Lock() - defer p.Mx.Unlock() + p.Mx.RLock() + defer p.Mx.RUnlock() log.D.C( func() string { return fmt.Sprintf(