react-scheduler icon indicating copy to clipboard operation
react-scheduler copied to clipboard

Fix performance for filter today events function

Open hoangqwe159 opened this issue 1 month ago • 0 comments

Fix Performance Regression in Recurring Event Timezone Conversion

Problen and fix demo

https://drive.google.com/file/d/1aLZ7Pyqvd9ilqmWYt0st8t-9bQjmfUtO/view?usp=sharing

Summary

This PR fixes a significant performance regression introduced in the recent timezone handling refactor for recurring events. The previous implementation was performing timezone conversions on every recurrence instance, causing O(n × r) complexity instead of O(n), where r = number of recurrences per event.

Problem

The recent changes to getRecurrencesForDate and filterTodayEvents introduced several performance issues:

  1. Redundant timezone conversions: Each recurrence instance was being converted individually instead of converting the base event once
  2. Expanded search window: Changed from 1-day to 2-day search window, generating more recurrences unnecessarily
  3. Increased computational overhead: For events with many recurrences (e.g., hourly meetings), this created significant bottlenecks

Example Impact

  • Before fix: Event with 100 daily recurrences → 100 Intl.DateTimeFormat calls
  • After fix: Event with 100 daily recurrences → 1 Intl.DateTimeFormat call

Changes

getRecurrencesForDate Function

  • Removed timeZone parameter from function signature
  • Removed timezone conversion logic that was being applied to each recurrence
  • Restored original 1-day search window: between(today, addDays(today, 1), true)
  • Kept the convertRRuleDateToDate utility for proper RRule date handling

filterTodayEvents Function

  • Restored pre-conversion pattern: convert each event's timezone ONCE before generating recurrences
  • Changed from getRecurrencesForDate(events[i], today, timeZone) to:
    const event = convertEventTimeZone(events[i], timeZone);
    for (const rec of getRecurrencesForDate(event, today)) {
    

Testing

  • [x] Verified recurring events display correctly across different timezones
  • [x] Confirmed performance improvement with high-frequency recurring events
  • [x] Tested edge cases: all-day events, multi-day events, single events
  • [x] Validated RRule date conversion still works correctly

Performance Metrics

  • Time complexity: Restored from O(n × r) to O(n)
  • Expected improvement: Up to 100x faster for events with 100+ recurrences

Breaking Changes

None - this is a performance optimization that maintains the same external behavior.

hoangqwe159 avatar Dec 30 '25 01:12 hoangqwe159