-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix performance issue on AllIntersections #14
Conversation
d053367
to
88a564a
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #14 +/- ##
==========================================
- Coverage 95.52% 94.88% -0.64%
==========================================
Files 6 6
Lines 670 861 +191
==========================================
+ Hits 640 817 +177
- Misses 18 32 +14
Partials 12 12 ☔ View full report in Codecov by Sentry. |
88a564a
to
37b87f8
Compare
This commit addresses a performance issue in the AllIntersections function, where the conditional for traversing the right side of the tree was evaluating to true most of the time. This led to unnecessary visits of right nodes, resulting in linear time complexity. More background on why this fix is correct: - Left is safe to prune when all lower nodes end before the start of the lookup interval (`Left.MaxEnd < start`). (Note: this case was already correct before this commit, but I reversed the inequality as I find it easier to reason about) - Right is safe to prune when all higher nodes start after the end of lookup interval (`end < Current.Start`). If the current node starts after the end of the lookup interval, we're guaranteed all its right nodes will also because they all start after the current node by definition. Fuzz testing yielded consistent results with original implementation. Benchmark showed ~30% speed improvement on average case (random intervals), and over 99.9% improvement in worst case (lookup interval at the far left of the tree). As expected, new implementation explores fewer nodes that can be evicted just as safely in advance.
37b87f8
to
22514f2
Compare
Hey @gilbsgilbs sorry for the late review. It's been a tough quarter at work. Your contribution makes total sense to me. Thank you! |
v1.4.1 published with the changes. Thank you again. |
No need to apologize. Thanks for the review and release 🙂. |
This commit addresses a performance issue in the AllIntersections function, where the conditional for traversing the right side of the tree was evaluating to true most of the time. This led to unnecessary visits of right nodes, resulting in linear time complexity.
More background on why this fix is correct:
Left.MaxEnd < start
). (Note: this case was already correct before this commit, but I reversed the inequality as I find it easier to reason about)end < Current.Start
). If the current node starts after the end of the lookup interval, we're guaranteed all its right nodes will also because they all start after the current node by definition.Fuzz testing yielded consistent results with original implementation. Benchmark showed ~30% speed improvement on average case (random intervals), and over 99.9% improvement in worst case (lookup interval at the far left of the tree). As expected, new implementation explores fewer nodes that can be evicted just as safely in advance.