Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/schedule/ScheduleContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default function ScheduleContainer({ initialSchedule, year }: Readonly<Sc
return initialSchedule;
}

const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession);
const savedSessionSet = new Set(savedSessionIds);
const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionSet.has(s.id) || s.isServiceSession);
Comment on lines +23 to +24
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 inside useMemo is a significant optimization over the previous $O(N \times M)$ approach, the savedSessionIds array is still being used in other parts of the application (like ScheduleContext.tsx) with $O(M)$ lookups.

For even better performance, consider storing savedSessionIds as a Set directly in the ScheduleContext. This would eliminate the need to rebuild the Set on every useMemo execution here and would also optimize the isSaved and toggleSession functions in the context from $O(M)$ to $O(1)$.


return initialSchedule.map((day) => ({
...day,
Expand Down
Loading