Skip to content

⚡ Bolt: Optimize schedule filtering#180

Open
anyulled wants to merge 1 commit into
mainfrom
jules-bolt-schedule-filtering-15198418608409947990
Open

⚡ Bolt: Optimize schedule filtering#180
anyulled wants to merge 1 commit into
mainfrom
jules-bolt-schedule-filtering-15198418608409947990

Conversation

@anyulled
Copy link
Copy Markdown
Owner

@anyulled anyulled commented Apr 24, 2026

💡 What:
Replaced Array.prototype.includes() with Set.prototype.has() when filtering user-saved schedule sessions.

🎯 Why:
The Array.includes() call inside a .filter() loop resulted in an O(N*M) time complexity operation, which is inefficient. By pre-computing a Set, the lookup becomes O(1), improving the overall filtering complexity to O(N+M).

📊 Impact:
Reduces the time complexity of schedule filtering, eliminating an O(N*M) loop inside a React useMemo hook, leading to faster re-renders when toggling the "My Schedule" filter.

🔬 Measurement:
Run npm run test and check the schedule component tests. Verify functionality by visiting the schedule page and toggling the "My Schedule" view with saved sessions.


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

Summary by CodeRabbit

  • Chores
    • Improved performance of the saved sessions filter by optimizing the session lookup mechanism for faster filtering when the saved-only view is enabled.

Replaces O(N) Array.includes() with O(1) Set.has() during the schedule filtering operation to improve performance.

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 24, 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 24, 2026 8:42am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

📝 Walkthrough

Walkthrough

The session filtering logic in ScheduleContainer.tsx was optimized to use a Set data structure instead of an array for savedSessionIds lookups. This improves performance from O(n) to O(1) when checking if a session ID is saved, while preserving the same filtering behavior.

Changes

Cohort / File(s) Summary
Performance Optimization
components/schedule/ScheduleContainer.tsx
Converted savedSessionIds array to a Set for faster O(1) lookup performance using Set.has() instead of Array.includes() when filtering sessions with showSavedOnly enabled.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A Set hops faster than an array's long trail,
Checking membership now won't fail,
O(1) lookup speeds up the day,
Sessions filter in the swifter way!

🚥 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 accurately reflects the main change: optimizing schedule filtering by replacing Array.includes() with Set.has() for O(1) lookups instead of O(N) operations.
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 jules-bolt-schedule-filtering-15198418608409947990

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 session filtering in ScheduleContainer.tsx by converting savedSessionIds to a Set to achieve O(1) lookup performance. Feedback suggests a further architectural improvement by storing savedSessionIds as a Set directly within the ScheduleContext to eliminate redundant conversions and optimize lookups globally.


const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession);
// Convert savedSessionIds to a Set to improve lookup performance from O(N) to O(1)
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 here successfully improves the filtering performance from O(N*M) to O(N+M), this conversion still occurs every time the useMemo for filteredSchedule is re-evaluated (e.g., when initialSchedule changes or when showSavedOnly is toggled).

For a more robust architectural improvement, consider storing savedSessionIds as a Set directly within the ScheduleContext. This would eliminate the need for local conversion and also optimize the isSaved check in the context, which currently uses Array.prototype.includes() (O(M) complexity). This would provide O(1) lookups throughout the application without repeated overhead.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
components/schedule/ScheduleContainer.tsx (1)

23-23: Tighten the inline comment to explain only the decision rationale

This comment mixes what and why; prefer keeping only the rationale (e.g., avoiding repeated linear lookups during filtering) to match repo comment conventions.

As per coding guidelines, "Code must be self-documenting. Only explain why non-obvious decisions were made in comments. DO NOT add inline comments explaining what code does."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/schedule/ScheduleContainer.tsx` at line 23, Tighten the inline
comment that currently reads "Convert savedSessionIds to a Set to improve lookup
performance from O(N) to O(1)" to only state the rationale: explain that
savedSessionIds is converted to a Set to avoid repeated linear lookups during
filtering (improves lookup complexity), and remove the "what" portion; update
the comment adjacent to the savedSessionIds conversion/Set instantiation in
ScheduleContainer (where savedSessionIds is used for filtering).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@components/schedule/ScheduleContainer.tsx`:
- Line 23: Tighten the inline comment that currently reads "Convert
savedSessionIds to a Set to improve lookup performance from O(N) to O(1)" to
only state the rationale: explain that savedSessionIds is converted to a Set to
avoid repeated linear lookups during filtering (improves lookup complexity), and
remove the "what" portion; update the comment adjacent to the savedSessionIds
conversion/Set instantiation in ScheduleContainer (where savedSessionIds is used
for filtering).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8041b204-ea37-4a41-b76d-bc5a101dc958

📥 Commits

Reviewing files that changed from the base of the PR and between c98052a and 0cd11c7.

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

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