From 860ad54c486849d55d0c3ab3e2573c015b8e8d98 Mon Sep 17 00:00:00 2001 From: anyulled <100741+anyulled@users.noreply.github.com> Date: Sat, 2 May 2026 08:34:27 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20ScheduleCont?= =?UTF-8?q?ainer=20filtering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- commit_body.txt | 4 ++++ components/schedule/ScheduleContainer.tsx | 8 +++++++- plan.md | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 commit_body.txt create mode 100644 plan.md diff --git a/commit_body.txt b/commit_body.txt new file mode 100644 index 00000000..f8be730d --- /dev/null +++ b/commit_body.txt @@ -0,0 +1,4 @@ +💡 What: Converted the `savedSessionIds` array into a `Set` prior to running the filter operation on grid sessions. +🎯 Why: To improve time complexity from O(N*M) (using `Array.includes()`) to O(N+M) (using `Set.has()`) during the filtering of sessions, where N is the total sessions and M is the number of saved sessions. +📊 Impact: Faster UI rendering and recalculations when filtering schedules by saved sessions, preventing sluggishness as arrays grow. +🔬 Measurement: Verify by interacting with "My Schedule" on pages with numerous sessions saved. diff --git a/components/schedule/ScheduleContainer.tsx b/components/schedule/ScheduleContainer.tsx index 33d877a4..268253bf 100644 --- a/components/schedule/ScheduleContainer.tsx +++ b/components/schedule/ScheduleContainer.tsx @@ -20,7 +20,13 @@ export default function ScheduleContainer({ initialSchedule, year }: Readonly sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession); + /* + * ⚡ Bolt: Convert array to Set for O(1) lookups instead of O(N) array includes + * Expected impact: Time complexity improves from O(N*M) to O(N+M) + * Measurement: Schedule renders faster when large numbers of sessions are saved + */ + const savedIdsSet = new Set(savedSessionIds); + const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedIdsSet.has(s.id) || s.isServiceSession); return initialSchedule.map((day) => ({ ...day, diff --git a/plan.md b/plan.md new file mode 100644 index 00000000..33730fc2 --- /dev/null +++ b/plan.md @@ -0,0 +1,16 @@ +1. **Optimize `filterSessions` in `ScheduleContainer.tsx`** + - The current implementation of `ScheduleContainer.tsx` uses `savedSessionIds.includes(s.id)` inside a `.filter()` loop which scales to O(N*M) where N is the number of sessions and M is the number of saved session IDs. + - We will replace this array check with a `Set` check. We'll add `const savedIdsSet = new Set(savedSessionIds);` outside the `filterSessions` function, and inside the function, we'll use `savedIdsSet.has(s.id)`. This will improve the lookup complexity from O(M) to O(1), improving the overall filtering complexity to O(N). + +2. **Run Tests and Linter** + - Execute `npm run test` and `npm run lint` to ensure the change does not break any tests or introduce linting issues. + +3. **Complete pre-commit steps to ensure proper testing, verification, review, and reflection are done.** + - Run the pre-commit script to run all final verifications. + +4. **Submit** + - Create a PR with the title format "⚡ Bolt: [improvement]" + - Describe What: The optimization implemented + - Describe Why: The performance problem it solves + - Describe Impact: Expected performance improvement + - Describe Measurement: How to verify the improvement From d5e3d21f244111a55c5e26b598d9e95838a177ae Mon Sep 17 00:00:00 2001 From: anyulled <100741+anyulled@users.noreply.github.com> Date: Sat, 2 May 2026 08:38:10 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20ScheduleCont?= =?UTF-8?q?ainer=20filtering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- commit_body.txt | 4 ---- plan.md | 16 ---------------- 2 files changed, 20 deletions(-) delete mode 100644 commit_body.txt delete mode 100644 plan.md diff --git a/commit_body.txt b/commit_body.txt deleted file mode 100644 index f8be730d..00000000 --- a/commit_body.txt +++ /dev/null @@ -1,4 +0,0 @@ -💡 What: Converted the `savedSessionIds` array into a `Set` prior to running the filter operation on grid sessions. -🎯 Why: To improve time complexity from O(N*M) (using `Array.includes()`) to O(N+M) (using `Set.has()`) during the filtering of sessions, where N is the total sessions and M is the number of saved sessions. -📊 Impact: Faster UI rendering and recalculations when filtering schedules by saved sessions, preventing sluggishness as arrays grow. -🔬 Measurement: Verify by interacting with "My Schedule" on pages with numerous sessions saved. diff --git a/plan.md b/plan.md deleted file mode 100644 index 33730fc2..00000000 --- a/plan.md +++ /dev/null @@ -1,16 +0,0 @@ -1. **Optimize `filterSessions` in `ScheduleContainer.tsx`** - - The current implementation of `ScheduleContainer.tsx` uses `savedSessionIds.includes(s.id)` inside a `.filter()` loop which scales to O(N*M) where N is the number of sessions and M is the number of saved session IDs. - - We will replace this array check with a `Set` check. We'll add `const savedIdsSet = new Set(savedSessionIds);` outside the `filterSessions` function, and inside the function, we'll use `savedIdsSet.has(s.id)`. This will improve the lookup complexity from O(M) to O(1), improving the overall filtering complexity to O(N). - -2. **Run Tests and Linter** - - Execute `npm run test` and `npm run lint` to ensure the change does not break any tests or introduce linting issues. - -3. **Complete pre-commit steps to ensure proper testing, verification, review, and reflection are done.** - - Run the pre-commit script to run all final verifications. - -4. **Submit** - - Create a PR with the title format "⚡ Bolt: [improvement]" - - Describe What: The optimization implemented - - Describe Why: The performance problem it solves - - Describe Impact: Expected performance improvement - - Describe Measurement: How to verify the improvement