Skip to content

Cache presence/stats packet serialization#748

Open
cmyui wants to merge 1 commit intomasterfrom
perf/cached-presence-stats
Open

Cache presence/stats packet serialization#748
cmyui wants to merge 1 commit intomasterfrom
perf/cached-presence-stats

Conversation

@cmyui
Copy link
Member

@cmyui cmyui commented Mar 2, 2026

Summary

  • Adds lazy caching of user_presence and user_stats packet serialization on each Player object, avoiding redundant re-serialization when the same player's packets are broadcast to many recipients
  • Cached bytes are invalidated when underlying data changes: privilege updates (update_privs, add_privs, remove_privs), full stats reload (stats_from_sql_full), status changes, and score submissions
  • Updates all call sites in cho.py (login handler, action change) and osu.py (score submission) to use cached packets

Test plan

  • mypy type checking passes (python -m mypy app/)
  • Verify login flow sends correct presence/stats to all online players
  • Verify action changes broadcast updated cached stats
  • Verify score submission invalidates and re-broadcasts stats
  • Verify privilege changes invalidate cached presence

🤖 Generated with Claude Code

Lazily serializes user_presence and user_stats packets on first access
and reuses the cached bytes until invalidated. Invalidation occurs when
privilege or stats data changes (priv updates, score submission, status
change, full stats reload). This avoids redundant re-serialization when
the same player's packets are sent to many recipients.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cmyui cmyui force-pushed the perf/cached-presence-stats branch from 9782344 to 482ea55 Compare March 2, 2026 09:43
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