⚡ Bolt: Optimize schedule filtering to use Set for O(1) lookups#171
⚡ Bolt: Optimize schedule filtering to use Set for O(1) lookups#171
Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@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. |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 37 minutes and 59 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request optimizes session filtering in the ScheduleContainer component by replacing array lookups with a Set for improved performance. The review feedback suggests further enhancing this by memoizing the Set independently to avoid redundant recreations when other useMemo dependencies change.
| } | ||
|
|
||
| const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession); | ||
| const savedSessionSet = new Set(savedSessionIds); |
There was a problem hiding this comment.
While creating a Set inside the useMemo is a significant improvement over Array.includes(), the savedSessionSet is currently recreated every time the useMemo re-runs (e.g., if initialSchedule changes while showSavedOnly is true). For even better performance, especially if the number of saved sessions grows very large, consider memoizing the Set independently or providing it directly from the ScheduleContext.
💡 What: The optimization implemented
Replaced the
Array.includes()check used during the schedule filtering process inScheduleContainer.tsxwith aSet.has()lookup.🎯 Why: The performance problem it solves$O(N \times M)$ time complexity where $N$ is the number of scheduled sessions and $M$ is the number of saved sessions. As the lists of sessions and user-saved sessions grow, filtering operations (e.g. when toggling the "My Schedule" tab) can cause lag on the main thread and janky rendering.
In
components/schedule/ScheduleContainer.tsx, theuseMemoblock used an array.includes()method inside a.filter()function when iterating oversavedSessionIds. This resulted in an📊 Impact: Expected performance improvement$O(1)$ $O(N \times M)$ to $O(N + M)$ during filtering, and effectively preventing main thread blocking on heavily saved schedules.
Converts the check to an amortized
Set.has()lookup, improving overall execution time complexity from🔬 Measurement: How to verify the improvement
localStorage.filterSessionscallback compared to the base branch.PR created automatically by Jules for task 401793108385955748 started by @anyulled