Skip to content

⚡ Optimize N+1 query in HomeViewModel with concurrent fetch - #13

Open
Salint wants to merge 1 commit into
mainfrom
perf-optimize-n-plus-1-query-8968536041597288309
Open

⚡ Optimize N+1 query in HomeViewModel with concurrent fetch#13
Salint wants to merge 1 commit into
mainfrom
perf-optimize-n-plus-1-query-8968536041597288309

Conversation

@Salint

@Salint Salint commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

💡 What: Refactored the participant user profile fetching in HomeViewModel.listenToChats to fetch user profiles concurrently using Future.wait instead of fetching them sequentially within a for loop.

🎯 Why: To resolve an N+1 query performance bottleneck. Previously, fetching the user profile for each chat was causing the total load time to scale linearly with the number of chats, which degraded responsiveness and chat loading speeds for users with many conversations.

📊 Measured Improvement: We created a benchmark simulating 20 chats with a modest 50ms simulated network delay per getUser fetch.

  • Baseline (Sequential): ~1000 ms
  • Optimized (Concurrent): ~60 ms
  • Improvement: Reduced latency by ~94% (a ~16x speedup) for the 20-element sample. The loading time is now roughly bounded by the slowest single query rather than the sum of all queries.

PR created automatically by Jules for task 8968536041597288309 started by @Salint

Refactored chat participant user fetching from sequential await loop to concurrent fetching using `Future.wait`.

Benchmark simulation metrics for 20 elements simulating a 50ms network delay per request:
- Baseline: ~1000 ms
- Optimized: ~60 ms

Co-authored-by: Salint <[email protected]>
@google-labs-jules

Copy link
Copy Markdown
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.

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