-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Optimize lexicographical_compare #65279
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
[libc++] Optimize lexicographical_compare #65279
Conversation
fec7ee6
to
d28be44
Compare
Can you please add benchmarks for types other than std::string is a good candidate for a test type. With both short and long strings. |
Please add a description of how you optimized the code. It's not at all clear after reading the diff. |
Please take a look at this godbolt. It looks like under optimized builds, apart from for I don't think that cost/benefit trade off has the correct balance. Convince me otherwise? |
@philnik777 Also, please include descriptions. IT took me an hour to realize this change only affects |
Could you share the link you were looking at?
This is only a draft, so I didn't bother writing a comment. This patch isn't ready for review yet. |
@philnik777 Please don't open pull requests for changes that aren't ready to review. I'll go ahead and close this. Please re-submit when you're ready. |
This is a draft. Drafts are for patches that are not ready for review. |
Drafts seem to prevent merging, not review. Is there a way to filter pull requests to non-draft libc++ PR's? If not, then I think we need to reconsider the purpose of drafts. What is the purpose of opening the draft if you didn't want review? |
Yes. It also prevents notifying people until it is made a PR.
It has multiple benefits:
|
It's a draft. You stated you don't want review comments yet. Are you going to address the comments I left?
You can do that in your own branch.
I'm going to be working to stop Draft PR from using shared resources. It's unfair to commits that are ready to go.
Again, link to your own github fork. Again, you either don't want feedback or you do. It's unclear from this conversation which it is, but it seems like you're having it both ways. |
68c2eb6
to
77c776a
Compare
e85cefc
to
86967cb
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
86967cb
to
708f75a
Compare
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.
LGTM with my comments applied. Thanks, this is a neat optimization.
708f75a
to
d5dedbc
Compare
d5dedbc
to
dcd5f8a
Compare
If the comparison operation is equivalent to < and that is a total order, we know that we can use equality comparison on that type instead to extract some information. Furthermore, if equality comparison on that type is trivial, the user can't observe that we're calling it. So instead of using the user-provided total order, we use std::mismatch, which uses equality comparison (and is vertorized). Additionally, if the type is trivially lexicographically comparable, we can go one step further and use std::memcmp directly instead of calling std::mismatch.
Benchmarks: