-
Notifications
You must be signed in to change notification settings - Fork 15
Optimise the RangeManager a bit since its now a lot more heavily used #1033
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
base: master
Are you sure you want to change the base?
Optimise the RangeManager a bit since its now a lot more heavily used #1033
Conversation
Summary of ChangesHello @rad-cord, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a critical performance enhancement for range management within the system. It introduces a new, highly efficient Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Unit test report (Python 3.9.24, Pydantic 1.10.22)307 tests 307 ✅ 11s ⏱️ Results for commit d410ebb. ♻️ This comment has been updated with latest results. |
Unit test report (Python 3.9.24, Pydantic 2.12.3)307 tests 307 ✅ 11s ⏱️ Results for commit d410ebb. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant performance optimization for RangeManager by replacing its list-based implementation with a new IntegerRangeSet class that uses bisect for more efficient range management. The changes are well-structured and include comprehensive unit and performance tests. My review focuses on further performance improvements, API design, and test clarity. Overall, this is a great improvement.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
SDK integration test report285 tests ±0 275 ✅ - 2 13m 0s ⏱️ - 5m 12s For more details on these failures, see this check. Results for commit d410ebb. ± Comparison against base commit dbabc87. ♻️ This comment has been updated with latest results. |
| """Performance regression tests for RangeManager.""" | ||
|
|
||
| import time | ||
|
|
||
| import pytest | ||
|
|
||
| from encord.common.range_manager import RangeManager | ||
| from encord.objects.frames import Range | ||
|
|
||
| NUM_RANGES = 100_000 | ||
|
|
||
| # Performance thresholds (in seconds) | ||
| # These are based on current performance and should alert if there's regression | ||
| ADD_RANGES_THRESHOLD = 1 | ||
| ADD_RANGE_SEQUENTIAL_THRESHOLD = 1 | ||
| INIT_FRAMES_THRESHOLD = 1 | ||
| GET_RANGES_THRESHOLD = 1 | ||
| INTERSECTION_THRESHOLD = 1 | ||
| REMOVE_RANGE_THRESHOLD = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crazy! Performance tests in the SDK? Love it.
| if start > end: | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if an error should be thrown here instead.
Maybe the code that calls this should be the one that checks it I guess? But curious about your thoughts on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. There are some scenarios where you don't want to throw an error - where it's particularly expensive or the app "must not crash", but neither apply here
Introduction and Explanation
Replace the RangeManager implementation, with one backed by
IntegerRangeSetwhich is a bit smarter about how it keeps tracks of ranges. Results in >100x speedup in situations where we deal with a lot of rangesTests
Future work
The RangeManager is now a wrapper around an external class, and in python even the overhead of a function call is noticeable