Skip to content

⚡ Bolt: Optimize saved sessions filtering with Set lookup#179

Open
anyulled wants to merge 1 commit intomainfrom
bolt/optimize-saved-sessions-filtering-9434671500239890305
Open

⚡ Bolt: Optimize saved sessions filtering with Set lookup#179
anyulled wants to merge 1 commit intomainfrom
bolt/optimize-saved-sessions-filtering-9434671500239890305

Conversation

@anyulled
Copy link
Copy Markdown
Owner

@anyulled anyulled commented Apr 23, 2026

💡 What:
Replaced the savedSessionIds.includes(s.id) array lookup with savedIdsSet.has(s.id) using a Set within the filteredSchedule useMemo hook in ScheduleContainer.

🎯 Why:
The includes method inside the filter callback creates an O(N*M) time complexity. By converting the lookup array to a Set outside the loop, the membership check becomes O(1), improving the overall operation to O(N+M). This prevents performance degradation when the number of saved sessions or total schedule sessions grows.

📊 Impact:
Reduces iteration overhead in the rendering pipeline. The time complexity for calculating the filtered schedule is optimized from O(N*M) to O(N+M).

🔬 Measurement:
Run npm run test and npm run lint to verify that the core schedule functionality remains perfectly intact.


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

Summary by CodeRabbit

  • Performance Improvements
    • Improved performance of session filtering in the schedule when using the saved sessions filter.

💡 What:
Replaced the `savedSessionIds.includes(s.id)` array lookup with `savedIdsSet.has(s.id)` using a `Set` within the `filteredSchedule` useMemo hook in `ScheduleContainer`.

🎯 Why:
The `includes` method inside the `filter` callback creates an O(N*M) time complexity. By converting the lookup array to a `Set` outside the loop, the membership check becomes O(1), improving the overall operation to O(N+M). This prevents performance degradation when the number of saved sessions or total schedule sessions grows.

📊 Impact:
Reduces iteration overhead in the rendering pipeline. The time complexity for calculating the filtered schedule is optimized from O(N*M) to O(N+M).

🔬 Measurement:
Run `npm run test` and `npm run lint` to verify that the core schedule functionality remains perfectly intact.

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 Apr 23, 2026

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

Project Deployment Actions Updated (UTC)
devbcn-nextjs Ready Ready Preview, Comment Apr 23, 2026 10:07am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 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: 1d42bd3f-79d8-47c2-a061-2fcc5a75e6de

📥 Commits

Reviewing files that changed from the base of the PR and between 7dc67df and 166b69f.

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

📝 Walkthrough

Walkthrough

Session filtering in ScheduleContainer now uses a precomputed Set for checking saved session IDs instead of the array .includes() method, improving lookup performance from O(n) to O(1) per check while maintaining identical filtering logic.

Changes

Cohort / File(s) Summary
Performance Optimization
components/schedule/ScheduleContainer.tsx
Replaced .includes() array lookup with Set .has() method for saved session ID checks, reducing algorithmic complexity without changing filter behavior.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A rabbit hops through the schedule with glee,
Sets are faster than arrays, you see!
From O(n) to O(1), the optimization's divine,
Performance now sparkles, it's truly fine! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: optimizing session filtering performance using Set lookup instead of array includes.
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-saved-sessions-filtering-9434671500239890305

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 replacing array inclusion checks with a Set for more efficient lookups. The review feedback suggests further refining this by memoizing the Set creation to avoid redundant conversions when the filtering state toggles.

}

const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession);
const savedIdsSet = 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 converting the array to a Set inside useMemo is a significant optimization for the filtering logic, creating a new Set instance on every memoization trigger (including when showSavedOnly toggles) can be further optimized. Consider memoizing the Set itself based only on savedSessionIds to avoid redundant conversions when the toggle state changes.

Suggested change
const savedIdsSet = new Set(savedSessionIds);
const savedIdsSet = useMemo(() => new Set(savedSessionIds), [savedSessionIds]);

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