-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Perf: fast CursorValues compare for StringViewArray using inline_key_… #16630
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: fast CursorValues compare for StringViewArray using inline_key_… #16630
Conversation
2551c37
to
95b8d73
Compare
@@ -493,13 +493,12 @@ impl<C: CursorValues> SortPreservingMergeStream<C> { | |||
if self.enable_round_robin_tie_breaker && cmp_node == 1 { | |||
match (&self.cursors[winner], &self.cursors[challenger]) { | |||
(Some(ac), Some(bc)) => { | |||
let ord = ac.cmp(bc); | |||
if ord.is_eq() { | |||
if ac == bc { |
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.
I also change this to using eq instead of compare first, this should also optimize some cases.
The latest PR shows almost 1.4 fast in my local MAC. |
🤖 |
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.
Thanks @zhuqi-lucas -- this looks wonderful
I kicked off some benchmark runs. I think we'll be ready to merge once the benchmarks are done and we add some tests.
Thank you again for pushing this along. BTW I have been using your work as a case study in how to do performance optimization https://x.com/andrewlamb1111/status/1940145869833085246 ❤️
@@ -288,6 +288,64 @@ impl CursorArray for StringViewArray { | |||
} | |||
} | |||
|
|||
/// Todo use arrow-rs side api after: <https://github.com/apache/arrow-rs/pull/7748> released |
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.
👍
/// ⇒ key("bar") < key("bar\0") | ||
/// ``` | ||
#[inline(always)] | ||
pub fn inline_key_fast(raw: u128) -> u128 { |
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.
While I know this is only temporary until we use the code in apache/arrow-rs#7748 , I think we should add some unit tests to make sure we don't accidentally break it
Perhaps we can just copy/paste the test_inline_key_fast_various_lengths_and_lexical
test from https://github.com/apache/arrow-rs/pull/7748/files#diff-160ecd8082d5d28081f01cdb08a898cb8f49b17149c7118bf96746ddaae24b4fR1168 ?
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.
Thank you @alamb for good point, addressed in latest PR!
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.
Do we need to port the same fix from
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.
Thank you @alamb,
I will port the apache/arrow-rs#7875 fix, after it merged!
🤖: Benchmark completed Details
|
🤖 |
🤖: Benchmark completed Details
|
…cas/arrow-datafusion into fast_sort_with_inlined_fast_key
Thank you very much @alamb! I really appreciate your kind words and support. I’ve also shared this work on my LinkedIn, it's been a fantastic experience joining the Apache DataFusion / Arrow Rust community and contributing to performance improvements. Looking forward to doing more! |
The Q1 regression seems noise, because it does not have utf8view sort key, the l_linenumber is Integer: SELECT l_linenumber, l_partkey
FROM lineitem
ORDER BY l_linenumber
|
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.
Thank you @zhuqi-lucas
…fast
Which issue does this PR close?
The arrow-rs compare improvement has been merged, we can apply it to CursorValues compare for StringViewArray in datafusion.
Related arrow-rs changes:
apache/arrow-rs#7748
Rationale for this change
What changes are included in this PR?
Optimizing the CursorValues compare for StringViewArray using fast inlined fast key, and compare performance.
Are these changes tested?
Yes
Are there any user-facing changes?
No