Skip to content

Conversation

@hoangqwe159
Copy link

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

  • Verified recurring events display correctly across different timezones
  • Confirmed performance improvement with high-frequency recurring events
  • Tested edge cases: all-day events, multi-day events, single events
  • 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 hoangqwe159 changed the title Viet/fix performance for filter today events function Fix performance for filter today events function Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant