Performance Guide
Audience: users and contributors.
Transport Characteristics
Section titled “Transport Characteristics”| Metric | WebRTC (P2P) | WebSocket relay | BroadcastChannel |
|---|---|---|---|
| Typical same-city latency | 8-30ms | 15-50ms | <1ms |
| Recommended room size | 8-12 peers | 500+ peers | same-browser only |
| Setup complexity | low | medium | low |
Binary codec note:
- WebRTC and relay websocket transports can switch from JSON to MessagePack after peer negotiation.
- BroadcastChannel stays JSON-only so same-origin tabs share a stable text envelope.
- Mixed-version or json-only peers automatically downgrade to JSON rather than failing the room.
Optimization
Section titled “Optimization”Cursor Throughput
Section titled “Cursor Throughput”const cursors = room.useCursors({ throttleMs: 16, smoothing: true,});Shared State
Section titled “Shared State”- Prefer
patchto reduce payload churn. - Avoid synchronizing large nested objects.
- Keep transient data in
events, notstate.
Awareness
Section titled “Awareness”- Keep awareness semantic (typing/focus/selection).
- Do not stream high-frequency pointer coordinates through awareness.
Scaling Path
Section titled “Scaling Path”- Start with
transport: 'auto'. - Let
autostay on BroadcastChannel for same-origin browser contexts. - Use WebRTC for smaller cross-machine rooms when direct mesh is viable.
- Move to websocket relay for sustained larger rooms or constrained networks.
- Add horizontal relay scaling as concurrency grows.
Redis-backed relay validation:
- Set
ROOMFUL_REDIS_URLon two relay instances that share the same Redis deployment. - Run
pnpm --filter @roomful/relay benchmark:rediswith that Redis URL in the environment. - Compare the Redis cross-instance benchmark to the single-instance baseline and keep added median latency under
5msfor local validation.
Relay load validation:
- Run
pnpm --filter @roomful/relay benchmark:load:steadyfor the single-room 100-peer baseline. - Run
pnpm --filter @roomful/relay benchmark:load:scale -- --redis-url redis://127.0.0.1:6379/0for the 500-peer, 50-room, 3-relay cluster scenario. - Run
pnpm --filter @roomful/relay benchmark:load:soak -- --redis-url redis://127.0.0.1:6379/0for the 30-minute soak and inspectbenchmarks/results/<run-id>/report.md. - Increase
--vuson the scale scenario to document the first concurrency level where latency thresholds or error-rate checks fail.
Validation Targets
Section titled “Validation Targets”- Stable cursor updates at expected peer count
- Predictable reconnect behavior under packet loss
- Controlled state payload growth over long sessions