Skip to content

Commit 850ac80

Browse files
keithwillcodedevin-ai-integration[bot]Udit-takkarhbjORbj
authored
perf: optimize date range intersection algorithm from O(n²) to O(n log n) (calcom#22076)
* feat: optimize date range intersection algorithm from O(n²) to O(n log n) - Replace nested forEach loops with two-pointer approach - Sort arrays once and traverse efficiently - Maintains exact same functionality and API - Improves performance for team scheduling scenarios Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * feat: add comprehensive stress test for intersect function performance - Add performance comparison test showing 22x improvement from O(n²) to O(n log n) - Include edge cases testing for correctness validation - Test with realistic data sizes (50 date ranges per user) - Demonstrate identical results between old and new algorithms - Provide timing measurements and performance logging Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * refactor: update stress test to focus on optimized algorithm performance - Remove old O(n²) algorithm comparison logic from test - Focus stress test on current optimized intersect function performance - Test with 400 total date ranges (4 users × 100 ranges each) - Maintain realistic data sizes for team scheduling scenarios - Execution time: 10.33ms for 400 ranges with 97 intersections found Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * docs: restore explanatory comment in intersect function - Add back comment explaining intersection logic as requested in PR review - Comment clarifies when intersected time ranges are added to results array - Addresses GitHub feedback from hbjORbj to revert comment removal Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * refactor: remove unnecessary intersectNew variable in edge cases test - Use intersect function directly instead of intersectNew variable assignment - Addresses GitHub feedback from keithwillcode to clean up test code - No functional changes to test logic or assertions Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * test: add comprehensive test coverage for intersect function - Add 27 comprehensive test cases covering all edge cases and scenarios - Test empty inputs, single arrays, overlapping ranges, containment - Add team scheduling scenarios and performance testing - Test unsorted input handling, cross-day scenarios, time precision - Ensure comprehensive coverage without knowing algorithm implementation - All tests pass with optimized O(n log n) algorithm - Performance test shows 8.50ms execution time for 400 date ranges Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * perf: improve intersect function in slots (calcom#22087) --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Benny Joo <sldisek783@gmail.com>
1 parent 5b1eb48 commit 850ac80

2 files changed

Lines changed: 450 additions & 37 deletions

File tree

0 commit comments

Comments
 (0)