From 42a62566b2fe89665b687cb5c819ef2c97021f1c Mon Sep 17 00:00:00 2001 From: anyulled <100741+anyulled@users.noreply.github.com> Date: Mon, 25 May 2026 08:27:20 +0000 Subject: [PATCH 1/3] feat: [performance improvement] Optimize saved session lookups in ScheduleContainer - 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> --- .jules/bolt.md | 1 + components/schedule/ScheduleContainer.tsx | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 9345ee7a..4b6e9916 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -2,3 +2,4 @@ **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. diff --git a/components/schedule/ScheduleContainer.tsx b/components/schedule/ScheduleContainer.tsx index 33d877a4..28179408 100644 --- a/components/schedule/ScheduleContainer.tsx +++ b/components/schedule/ScheduleContainer.tsx @@ -20,7 +20,9 @@ export default function ScheduleContainer({ initialSchedule, year }: Readonly sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession); + const savedIdsSet = new Set(savedSessionIds); + + const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedIdsSet.has(s.id) || s.isServiceSession); return initialSchedule.map((day) => ({ ...day, From d522ce14e45445f0ddce3987663ad3d700b795b1 Mon Sep 17 00:00:00 2001 From: anyulled <100741+anyulled@users.noreply.github.com> Date: Mon, 25 May 2026 08:40:31 +0000 Subject: [PATCH 2/3] feat: [performance improvement] Optimize saved session lookups in ScheduleContainer - 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> --- .jules/bolt.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 4b6e9916..fb1d76cf 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,5 +1,7 @@ ## 2024-05-18 - Avoid array spreads inside loops for Map grouping **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. +## 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. From e79456f840d8e52f3dcd1482dc75f16150fd494e Mon Sep 17 00:00:00 2001 From: anyulled <100741+anyulled@users.noreply.github.com> Date: Mon, 25 May 2026 08:48:09 +0000 Subject: [PATCH 3/3] feat: [performance improvement] Optimize saved session lookups in ScheduleContainer - 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> --- .jules/bolt.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index fb1d76cf..08c67ca1 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,7 +1,8 @@ ## 2024-05-18 - Avoid array spreads inside loops for Map grouping **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. + ## 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. +**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.