-
-
Notifications
You must be signed in to change notification settings - Fork 480
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
perf(linter): use binary_search instead of contains #4446
base: main
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #4446 will not alter performanceComparing Summary
|
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.
Can we enforce this at the type-level somehow? The obvious solution would be to use a BtreeSet
instead. I’m a bit afraid someone would add an entry and overlook the fact they need to be ordered, and we’d have a bug.
We could add unit tests as we did for the sorted arrays of JS builtins. |
Adding tests would be another approach indeed, but do we know the benefit of this approach to begin with? If there are no benchmarks, we're just complicating trivial functionality for unclear gain. It could even very well be that we're making things slower with this approach: https://www.reddit.com/r/rust/comments/1anlbui/comment/kpxl77q/ |
Yes, indeed, For small arrays, linear search is always the fastest approach. It is unclear to me what "small" is. The link you shared suggests I tend to use linear search for very small arrays (8 items or fewer). We could evaluate if the number should be higher. For quite-small arrays binary search should be good enough. By the way, if we write tests to check order we could use the recently stabilized is_sorted method. |
0f26644
to
9a55fc8
Compare
Summary
Replace all
.contains
with.binsearch
.Test Plan
Added tests to ensure values are sorted.