⚡ Optimize Redis usage in player view broadcast#13
Conversation
Replaced N+1 Redis calls in `get_player_view` loop with a single `MGET` call in `broadcast_filtered_states`. - Added `get_all_player_presence` to `GameService` - Updated `get_player_view` to accept optional `presence_map` - Reduced Redis calls from N to 1 per broadcast cycle. Co-authored-by: WeixuanZ <39925558+WeixuanZ@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Replaced N+1 Redis calls in `get_player_view` loop with a single `MGET` call in `broadcast_filtered_states`. - Added `get_all_player_presence` to `GameService` - Updated `get_player_view` to accept optional `presence_map` - Reduced Redis calls from N to 1 per broadcast cycle. Co-authored-by: WeixuanZ <39925558+WeixuanZ@users.noreply.github.com>
💡 What:
Optimized
get_player_viewandbroadcast_filtered_statesto batch presence checks.get_all_player_presencemethod toGameServiceto fetch presence for all players in one go.get_player_viewto accept an optionalpresence_map.broadcast_filtered_statesinbackend/app/api/routers/rooms.pyto fetch presence once and pass it down.🎯 Why:
Previously, broadcasting game state to N players resulted in N separate calls to
get_player_view, each triggering a Redismgetfor presence. This caused N round-trips to Redis.With this change, presence for all players is fetched once per broadcast, reducing Redis calls from N (per connected player) to 1.
📊 Measured Improvement:
Benchmark with N=50 players:
PR created automatically by Jules for task 8902105928956179380 started by @WeixuanZ