Skip to content

⚡ Bolt: Optimize array grouping in schedule generation#203

Merged
anyulled merged 2 commits into
mainfrom
bolt/optimize-use-schedule-map-grouping-16912068490767410867
May 7, 2026
Merged

⚡ Bolt: Optimize array grouping in schedule generation#203
anyulled merged 2 commits into
mainfrom
bolt/optimize-use-schedule-map-grouping-16912068490767410867

Conversation

@anyulled
Copy link
Copy Markdown
Owner

@anyulled anyulled commented May 7, 2026

💡 What: Replaced the array spread operator ([...existing, session]) with an in-place .push(session) operation inside the nested loop used for grouping GridSession items by time slot in hooks/useSchedule.ts.
🎯 Why: The previous implementation created a new array and copied all existing items into it on every iteration for the same time key. In loops, this pattern leads to amortized O(N^2) memory allocations and unnecessary garbage collection overhead.
📊 Impact: Transforms the grouping operation from an amortized O(N^2) time and space complexity to an amortized O(N) complexity (O(1) per insertion). This directly reduces memory thrashing during schedule parsing, leading to slightly faster static generation times for schedule pages.
🔬 Measurement: Run npm run test -- __tests__/schedule_performance.test.ts to ensure schedule fetching remains performant and correct. Compare build times of app/[year]/schedule/page.tsx before and after the change using the Next.js build profiler.


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

Summary by CodeRabbit

  • Documentation

    • Added dated performance guidance recommending in-place array appends over repeated array-spread in loops to reduce allocations and GC overhead.
  • Refactor

    • Optimized schedule-building logic to append items into existing per-time arrays (reducing allocations), improving runtime and memory behavior.

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

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

Project Deployment Actions Updated (UTC)
devbcn-nextjs Error Error May 7, 2026 1:40pm

Request Review

@qodo-code-review
Copy link
Copy Markdown

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 518cbc9d-7924-47da-8c69-af486a42fce5

📥 Commits

Reviewing files that changed from the base of the PR and between ec5e707 and 15a4956.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • hooks/useSchedule.ts

📝 Walkthrough

Walkthrough

This PR adds a dated note documenting that array spread in loops causes extra allocations and updates getSchedule to build sessionsByTime by initializing arrays once and appending with .push() instead of recreating arrays via spread.

Changes

Performance Optimization: Array Mutation in Schedule Grouping

Layer / File(s) Summary
Performance Guidance Documentation
.jules/bolt.md
New dated entry (2024-05-18) explains that using array spread inside loops causes excessive allocations and recommends .push() with an ESLint-friendly initialization fallback.
sessionsByTime Map construction
hooks/useSchedule.ts
getSchedule now initializes per-time arrays only when missing and appends sessions using .push(); timeSlots generation and sorting remain unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • anyulled/devbcn-nextjs#24: Both PRs touch hooks/useSchedule.ts; this PR changes array-building to use mutation, while that PR wraps getSchedule with React.cache.

Suggested labels

size/size/M

Poem

🐰 Arrays hop, they copy and grow,
Spreading crumbs where memory flows.
A gentle push, in-place and neat,
Keeps GC light and code more fleet.
A rabbit nods — performance wins, we know.

🚥 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 and specifically summarizes the main change: optimizing array grouping in schedule generation by replacing array spread with in-place operations, which directly matches the primary modification in hooks/useSchedule.ts.
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-use-schedule-map-grouping-16912068490767410867

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.jules/bolt.md (1)

1-4: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix Markdown formatting to unblock CI lint

prettier --check is currently failing for this file per pipeline output. Please run Prettier on .jules/bolt.md (or project-wide) so CI passes.

🤖 Prompt for 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.

In @.jules/bolt.md around lines 1 - 4, The Markdown file `.jules/bolt.md` is
failing Prettier; run Prettier to reformat this file (or project-wide) and
commit the changes so `prettier --check` passes; specifically reformat the
section titled "2024-05-18 - Avoid array spreads inside loops for Map grouping"
to match the project's Prettier rules and then push the updated
`.jules/bolt.md`.
🤖 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.

Outside diff comments:
In @.jules/bolt.md:
- Around line 1-4: The Markdown file `.jules/bolt.md` is failing Prettier; run
Prettier to reformat this file (or project-wide) and commit the changes so
`prettier --check` passes; specifically reformat the section titled "2024-05-18
- Avoid array spreads inside loops for Map grouping" to match the project's
Prettier rules and then push the updated `.jules/bolt.md`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 76a3ce08-7381-4c30-b2b3-d9780b386ed1

📥 Commits

Reviewing files that changed from the base of the PR and between edb5c60 and ec5e707.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • hooks/useSchedule.ts

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 introduces a performance optimization to avoid O(N^2) memory allocations by replacing array spreads with .push() in loops, specifically within hooks/useSchedule.ts, and documents this pattern in .jules/bolt.md. Feedback suggests that getSchedule should implement a strict mode for build-time safety to match other data fetching hooks. Additionally, it is recommended to remove the verbose, branded inline comments and apply the same optimization to groupTalksByTrack in hooks/useTalks.ts for consistency.

Comment thread hooks/useSchedule.ts
Comment thread hooks/useSchedule.ts
Comment thread .jules/bolt.md
Copy link
Copy Markdown
Owner Author

@anyulled anyulled left a comment

Choose a reason for hiding this comment

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

@jules you have reviews to address.

Comment thread .jules/bolt.md
Comment thread hooks/useSchedule.ts
Comment thread hooks/useSchedule.ts
anyulled and others added 2 commits May 7, 2026 15:39
Replaced O(N^2) array spread operation inside a nested loop with an
amortized O(1) in-place array push when grouping sessions by time in
`hooks/useSchedule.ts`. Also added a journal entry in `.jules/bolt.md`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Replaced O(N^2) array spread operation inside a nested loop with an
amortized O(1) in-place array push when grouping sessions by time in
`hooks/useSchedule.ts`. Also added a journal entry in `.jules/bolt.md`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@anyulled anyulled force-pushed the bolt/optimize-use-schedule-map-grouping-16912068490767410867 branch from 6d67e81 to 15a4956 Compare May 7, 2026 13:39
@anyulled anyulled merged commit 215c97f into main May 7, 2026
9 of 11 checks passed
@anyulled anyulled deleted the bolt/optimize-use-schedule-map-grouping-16912068490767410867 branch May 7, 2026 13:43
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