Skip to content

⚡ Optimize active user lookups in ConnectionManager#8

Open
the-asind wants to merge 1 commit intomainfrom
optimize-websocket-lookups-2399309273402612887
Open

⚡ Optimize active user lookups in ConnectionManager#8
the-asind wants to merge 1 commit intomainfrom
optimize-websocket-lookups-2399309273402612887

Conversation

@the-asind
Copy link
Owner

💡 What: Implemented reverse mapping dictionaries (project_user_ids and script_user_ids) in ConnectionManager to store sets of user IDs indexed by project and script IDs.
🎯 Why: The previous implementation iterated over all active user sessions ($O(N)$), which was inefficient for large numbers of users.
📊 Measured Improvement:
Benchmark results for get_script_active_users:

  • 100 users: 9.31 μs -> 0.39 μs (~24x speedup)
  • 1000 users: 107.51 μs -> 0.37 μs (~290x speedup)
  • 5000 users: 586.15 μs -> 0.34 μs (~1700x speedup)

Benchmark results for get_project_active_users:

  • 100 users: 15.71 μs -> 0.37 μs (~42x speedup)
  • 1000 users: 148.53 μs -> 0.34 μs (~430x speedup)
  • 5000 users: 851.88 μs -> 0.34 μs (~2500x speedup)

The new implementation provides consistent $O(M)$ performance where $M$ is the number of users in the specific project or script, independent of the total number of connected users.


PR created automatically by Jules for task 2399309273402612887 started by @the-asind

- Add project_user_ids and script_user_ids reverse mappings
- Update connection/disconnection methods to maintain mappings
- Refactor retrieval methods to use optimized lookups
- Improve performance from O(N) to O(M) for user listings

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link

👋 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.

@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

Warning

Rate limit exceeded

@the-asind has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2dfe894d-1fff-4b8c-860c-34a4c2534eca

📥 Commits

Reviewing files that changed from the base of the PR and between 5200141 and 3d407fc.

📒 Files selected for processing (1)
  • backend/app/services/websocket.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch optimize-websocket-lookups-2399309273402612887

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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