Skip to content
Open
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 savedSessionIdsSet = new Set(savedSessionIds);
const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIdsSet.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 savedSessionIds to a Set here is a great optimization that reduces the filtering complexity to O(N + M), we still incur an O(N) cost to reconstruct the Set on every memoization run when savedSessionIds or initialSchedule changes.

A more holistic improvement would be to store savedSessionIds as a Set<string> directly in ScheduleContext. This would:

  • Eliminate the need to reconstruct the Set here (making this O(1) setup).
  • Optimize isSaved in ScheduleContext from O(N) to O(1) (currently using Array.prototype.includes).
  • Optimize toggleSession in ScheduleContext from O(N) to O(1).

Since ScheduleContext.tsx is not modified in this PR, you can consider this as a follow-up refactoring.


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