Skip to content

feat: [performance improvement] Optimize saved session lookups in ScheduleContainer#238

Open
anyulled wants to merge 3 commits into
mainfrom
bolt/optimize-schedule-filtering-11304026006692388371
Open

feat: [performance improvement] Optimize saved session lookups in ScheduleContainer#238
anyulled wants to merge 3 commits into
mainfrom
bolt/optimize-schedule-filtering-11304026006692388371

Conversation

@anyulled
Copy link
Copy Markdown
Owner

@anyulled anyulled commented May 25, 2026

💡 What: Convert savedSessionIds array to a Set before filtering sessions.
🎯 Why: Using .includes() inside .filter() results in an O(N*M) time complexity. Using a Set improves this to O(N+M), preventing performance bottlenecks when users have many saved sessions.
📊 Impact: Reduces time spent filtering schedule sessions, preventing main thread blocking and ensuring smoother re-renders when toggling "My Schedule".
🔬 Measurement: Verify by saving multiple sessions and toggling the "My Schedule" filter. Profiling the React render will show reduced time in useMemo.


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

Summary by CodeRabbit

Release Notes

  • Performance
    • Improved performance of saved session filtering for better responsiveness when browsing large session lists.

Review Change Stack

…eduleContainer

- Convert `savedSessionIds` array to a `Set` before filtering sessions.
- Using `.includes()` inside `.filter()` results in an O(N*M) time complexity. Using a `Set` improves this to O(N+M), preventing performance bottlenecks when users have many saved sessions.

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 25, 2026

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

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

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 25, 2026

Warning

Review limit reached

@anyulled, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 39 minutes and 15 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b1adf297-751c-41d0-8882-87855d85aca9

📥 Commits

Reviewing files that changed from the base of the PR and between 42a6256 and e79456f.

📒 Files selected for processing (1)
  • .jules/bolt.md
📝 Walkthrough

Walkthrough

This PR optimizes session filtering in ScheduleContainer by replacing array includes() checks with a Set-based lookup for O(1) membership tests, improving filter complexity from O(N*M) to O(N+M). A performance guidance note documents the pattern in bolt.md.

Changes

Set-based lookup optimization in ScheduleContainer

Layer / File(s) Summary
Set-based lookup optimization in ScheduleContainer
components/schedule/ScheduleContainer.tsx, .jules/bolt.md
ScheduleContainer's "saved only" filter now builds a Set from savedSessionIds and uses has() for O(1) checks instead of includes(), improving from O(N*M) to O(N+M). The optimization is documented in bolt.md with a dated performance guidance note.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

size/size/M

Poem

🐰 A speedy hop through sets we go,
Arrays shrink where fast streams flow,
O(N*M) bows goodbye,
Set.has() reaches for the sky—
Performance hops more true today! ✨

🚥 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 'feat: [performance improvement] Optimize saved session lookups in ScheduleContainer' accurately describes the main change—optimizing session filtering via Set-based lookups for O(N+M) performance.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt/optimize-schedule-filtering-11304026006692388371

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 improves performance in ScheduleContainer.tsx by converting savedSessionIds to a Set to optimize filtering from O(N*M) to O(N+M). It also adds a corresponding entry to the .jules/bolt.md documentation. Feedback was provided regarding the documentation entry, which incorrectly used literal newline characters (\n) instead of actual line breaks, potentially breaking the markdown rendering.

Comment thread .jules/bolt.md Outdated

**Learning:** In Next.js/React applications, when grouping items (like schedules or talks) into a `Map` where the values are arrays, using the array spread operator `[...existing, item]` inside a loop (like `forEach` or `map`) causes amortized O(N^2) memory allocations and unnecessary Garbage Collection overhead.
**Action:** Always use `.push()` on the existing array reference if the data structure permits local mutation. For strict ESLint configurations enforcing `no-restricted-syntax`, extract the existing array, push to it, and handle the fallback elegantly (`if (!existing) { map.set(key, [item]); } else { existing.push(item); }`).
## 2024-05-25 - Avoid array includes inside array filter operations\n\n**Learning:** In Next.js/React applications, when filtering a list of items based on their presence in another array (e.g., `savedSessionIds.includes(s.id)` inside a `filter` function), it leads to an O(N * M) time complexity. This can cause performance bottlenecks and block the main thread, especially if the arrays are large.\n**Action:** Convert the lookup array into a `Set` before the filtering loop. Use `set.has(id)` inside the `filter` function to achieve O(N + M) time complexity.
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

The new entry in the markdown file contains literal \n characters instead of actual newlines. This will cause the text to be rendered as a single line with visible \n strings rather than properly formatted markdown blocks. It should follow the multi-line format used in the previous entry for consistency and readability.

Suggested change
## 2024-05-25 - Avoid array includes inside array filter operations\n\n**Learning:** In Next.js/React applications, when filtering a list of items based on their presence in another array (e.g., `savedSessionIds.includes(s.id)` inside a `filter` function), it leads to an O(N * M) time complexity. This can cause performance bottlenecks and block the main thread, especially if the arrays are large.\n**Action:** Convert the lookup array into a `Set` before the filtering loop. Use `set.has(id)` inside the `filter` function to achieve O(N + M) time complexity.
## 2024-05-25 - Avoid array includes inside array filter operations
**Learning:** In Next.js/React applications, when filtering a list of items based on their presence in another array (e.g., `savedSessionIds.includes(s.id)` inside a `filter` function), it leads to an O(N * M) time complexity. This can cause performance bottlenecks and block the main thread, especially if the arrays are large.
**Action:** Convert the lookup array into a `Set` before the filtering loop. Use `set.has(id)` inside the `filter` function to achieve O(N + M) time complexity.

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.jules/bolt.md:
- Line 5: Replace the literal escaped newline sequence `\n\n` in the markdown
heading text "2024-05-25 - Avoid array includes inside array filter operations"
with real line breaks (actual blank lines) so the content is rendered as
separate paragraphs; edit the .jules/bolt.md entry to remove the
backslash-escaped `\n\n` and insert actual newlines between the lines of the
heading, Learning, and Action sections to satisfy Prettier and fix rendering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 87ba655d-b934-4d8b-86bb-b5b6801de408

📥 Commits

Reviewing files that changed from the base of the PR and between 6513720 and 42a6256.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • components/schedule/ScheduleContainer.tsx

Comment thread .jules/bolt.md Outdated
…eduleContainer

- Convert `savedSessionIds` array to a `Set` before filtering sessions.
- Using `.includes()` inside `.filter()` results in an O(N*M) time complexity. Using a `Set` improves this to O(N+M), preventing performance bottlenecks when users have many saved sessions.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
…eduleContainer

- Convert `savedSessionIds` array to a `Set` before filtering sessions.
- Using `.includes()` inside `.filter()` results in an O(N*M) time complexity. Using a `Set` improves this to O(N+M), preventing performance bottlenecks when users have many saved sessions.
- Formatted .jules/bolt.md to fix Prettier CI check.

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