Files
calendar/packages/lib
Keith WilliamsGitHubkeith@cal.com <keithwillcode@gmail.com>Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>Udit TakkarBenny Joo
850ac8092f perf: optimize date range intersection algorithm from O(n²) to O(n log n) (#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 (#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>
2025-07-04 00:00:31 +01:00
..
2024-11-13 15:14:31 -05:00
2025-05-28 02:38:20 +01:00
2024-04-27 18:14:37 +02:00
2025-07-02 23:06:28 +05:30
2023-07-28 15:11:44 +00:00
2025-03-20 21:30:51 -03:00
2024-03-08 15:13:29 +00:00
2022-05-26 11:07:14 -06:00
2022-03-23 15:00:30 -07:00
2022-03-23 15:00:30 -07:00
2023-04-25 19:39:47 -03:00
2025-04-21 05:33:00 +00:00
2024-10-04 13:44:50 -07:00
2024-05-10 08:47:57 +01:00
2025-03-20 21:30:51 -03:00
2024-10-24 09:10:27 -04:00
2023-11-11 11:16:35 +00:00