Perf: Gateway broadcast clones payload per recipient; unregister scans all channels #85

Closed
opened 2026-07-08 02:40:32 +00:00 by icub3d · 0 comments
Owner

Category: Performance — found in code review 2026-07-07.

Problem

server/src/gateway/registry.rs:76broadcast_to_channel/send_to_user/broadcast_all do sender.send(payload.to_string()) inside the loop: one heap allocation of the same JSON per recipient. A busy channel with N subscribers = N copies. The read lock is also held across all N allocations.

Related: unregister (registry.rs:51) scans every channel's subscription set on each disconnect (O(channels)), even channels the connection never joined.

Fix

  • Make the outbound channel carry Arc<str> (or Arc<String>); build the payload once, clone the pointer per recipient.
  • Track each connection's subscribed channels so unregister only touches relevant channels.
**Category: Performance** — found in code review 2026-07-07. ## Problem `server/src/gateway/registry.rs:76` — `broadcast_to_channel`/`send_to_user`/`broadcast_all` do `sender.send(payload.to_string())` inside the loop: one heap allocation of the same JSON per recipient. A busy channel with N subscribers = N copies. The read lock is also held across all N allocations. Related: `unregister` (`registry.rs:51`) scans **every** channel's subscription set on each disconnect (O(channels)), even channels the connection never joined. ## Fix - [ ] Make the outbound channel carry `Arc<str>` (or `Arc<String>`); build the payload once, clone the pointer per recipient. - [ ] Track each connection's subscribed channels so `unregister` only touches relevant channels.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
icub3d/decentcom#85
No description provided.