Skip to content

Conversation

@WeixuanZ
Copy link
Owner

@WeixuanZ WeixuanZ commented Feb 1, 2026

πŸ’‘ What:

  • Modified Game.get_view_for_player and GameService.get_player_view to accept an optional full_schema argument.
  • Updated broadcast_filtered_states in backend/app/api/routers/rooms.py to generate the full game schema once and pass it to the view generation function for each player.

🎯 Why:

  • Previously, get_view_for_player called self.to_schema() internally every time.
  • When broadcasting state to $N$ players, this resulted in $N$ redundant full game serializations (Pydantic model creation), which is CPU intensive.
  • This optimization reduces the complexity from $O(N \times \text{schema_cost})$ to $O(\text{schema_cost}) + O(N \times \text{filter_cost})$.

πŸ“Š Measured Improvement:

  • Baseline: ~0.1591 seconds for 100 players calling get_view_for_player.
  • Optimized: ~0.0720 seconds for 100 players.
  • Improvement: ~54.77% reduction in processing time for state broadcast generation.

PR created automatically by Jules for task 15313983742005791179 started by @WeixuanZ

Avoid redundant calls to `Game.to_schema()` when broadcasting game state to multiple players.
Generate the full schema once and pass it to `get_view_for_player` for each player.

Benchmark showed ~55% improvement (0.159s -> 0.072s for 100 players).

Co-authored-by: WeixuanZ <39925558+WeixuanZ@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

πŸ‘‹ 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@WeixuanZ WeixuanZ closed this Feb 1, 2026
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.

2 participants