Skip to content

perf(core): batch matchmaking I/O and implement bulk presence heartbeat#6

Merged
AlpNuhoglu merged 1 commit into
mainfrom
perf/matchmaking-presence-io-batching
Jun 22, 2026
Merged

perf(core): batch matchmaking I/O and implement bulk presence heartbeat#6
AlpNuhoglu merged 1 commit into
mainfrom
perf/matchmaking-presence-io-batching

Conversation

@AlpNuhoglu

Copy link
Copy Markdown
Owner

This refactor eliminates the two most critical bottlenecks in the hot path: the N+1 Redis network round-trips in matchmaking and the goroutine/TCP explosion in presence heartbeats.

Key changes:

  • Matchmaking (feat(messaging): add NATS JetStream event bus with durable consumers #1): Replaced sequential per-pair createRoom calls with a single tick-level pipeline (SaveMany and RemoveBatch). Collapsed thousands of spans into a single batch span.
  • Presence (fix(nats): resolve golangci-lint failures (gosec G118, revive) #2): Replaced per-player heartbeat goroutines with a single /presence/heartbeat/bulk POST request. Implemented a 2-pass pipelined approach (EXPIRE + heal EVAL) for steady-state O(1) RTT.
  • Cluster Readiness: Replaced all TxPipeline occurrences with standard Pipeline() and removed cross-slot assumptions, ensuring seamless future migration to Redis Cluster.
  • Memory: Eliminated hidden heap escapes (boxing) in ZRem and pre-allocated all slices with exact capacities to reduce GC pressure.
  • Fix: Resolved pipeline NOSCRIPT error by replacing EvalSha fallback with explicit Eval in the heal pass.

This refactor eliminates the two most critical bottlenecks in the hot path:
the N+1 Redis network round-trips in matchmaking and the goroutine/TCP
explosion in presence heartbeats.

Key changes:
- Matchmaking (#1): Replaced sequential per-pair `createRoom` calls with a
  single tick-level pipeline (`SaveMany` and `RemoveBatch`). Collapsed thousands
  of spans into a single batch span.
- Presence (#2): Replaced per-player heartbeat goroutines with a single
  `/presence/heartbeat/bulk` POST request. Implemented a 2-pass pipelined
  approach (EXPIRE + heal EVAL) for steady-state O(1) RTT.
- Cluster Readiness: Replaced all `TxPipeline` occurrences with standard
  `Pipeline()` and removed cross-slot assumptions, ensuring seamless future
  migration to Redis Cluster.
- Memory: Eliminated hidden heap escapes (boxing) in `ZRem` and pre-allocated
  all slices with exact capacities to reduce GC pressure.
- Fix: Resolved pipeline `NOSCRIPT` error by replacing `EvalSha` fallback
  with explicit `Eval` in the heal pass.
@AlpNuhoglu AlpNuhoglu merged commit 75c697e into main Jun 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant