Skip to content

⚡ Bolt: Optimize schedule filtering with Set lookup#232

Open
anyulled wants to merge 1 commit into
mainfrom
bolt/optimize-schedule-filtering-4801011960425649429
Open

⚡ Bolt: Optimize schedule filtering with Set lookup#232
anyulled wants to merge 1 commit into
mainfrom
bolt/optimize-schedule-filtering-4801011960425649429

Conversation

@anyulled
Copy link
Copy Markdown
Owner

@anyulled anyulled commented May 18, 2026

💡 What: Converted the savedSessionIds array into a Set outside of the session filtering loops in ScheduleContainer.tsx.
🎯 Why: The original code used Array.includes() inside an Array.filter() method. This resulted in O(N*M) time complexity, where N is the number of saved sessions and M is the total number of sessions. Using a Set brings the complexity down to O(N+M) because Set.has() has O(1) time complexity.
📊 Impact: Reduces CPU time when re-rendering the schedule grid when a user clicks the "My Schedule" button, especially when many sessions are loaded or saved.
🔬 Measurement: Verify by rendering the schedule grid with a large mock dataset of DailySchedule entries and a large list of savedSessionIds, observing the time required to switch to "My Schedule" view.


PR created automatically by Jules for task 4801011960425649429 started by @anyulled

Summary by CodeRabbit

  • Refactor
    • Improved performance of session filtering in schedule management for faster schedule display updates.

Review Change Stack

Convert the savedSessionIds array to a Set before performing lookups inside
the filter loop to reduce time complexity from O(N*M) to O(N+M).

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@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.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
devbcn-nextjs Error Error May 18, 2026 8:45am

Request Review

@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3dabf1be-32b4-4d37-861a-a937a43f801f

📥 Commits

Reviewing files that changed from the base of the PR and between 96da992 and 9274a6a.

📒 Files selected for processing (1)
  • components/schedule/ScheduleContainer.tsx

📝 Walkthrough

Walkthrough

ScheduleContainer optimizes session filtering by building a Set from savedSessionIds and using Set.has() for membership checks instead of Array.includes(), reducing the lookup time complexity from O(n) to O(1) when filtering sessions in "My Schedule" mode.

Changes

Session Filtering Performance

Layer / File(s) Summary
Set-based session ID lookup
components/schedule/ScheduleContainer.tsx
savedSessionIdsSet is constructed from savedSessionIds and replaces array-based includes() checks with Set.has() for O(1) session membership validation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested labels

size/XS

Poem

🐰 A tiny change, yet swift and bright,
Set lookups now outrun the night,
From linear search to constant time,
This rabbit hops a code sublime! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: optimizing schedule filtering by replacing Array.includes() with Set lookup for better performance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt/optimize-schedule-filtering-4801011960425649429

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes the session filtering logic in ScheduleContainer.tsx by converting the savedSessionIds array into a Set, which improves the lookup complexity from O(N) to O(1). The reviewer suggests further improving this by storing the IDs as a Set directly within the ScheduleContext to avoid recreating the Set on every render and to provide performance benefits to other components that consume this data.

}

const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession);
const savedSessionIdsSet = new Set(savedSessionIds);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this local optimization correctly reduces the filtering complexity from O(N*M) to O(N+M), consider storing savedSessionIds as a Set directly within the ScheduleContext. This would eliminate the need to recreate the Set on every re-render of this component and would also optimize the isSaved check (currently O(N) in the context) for all components consuming it, such as SessionCard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant