[
https://issues.apache.org/jira/browse/ARROW-8129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17060602#comment-17060602
]
Yibo Cai commented on ARROW-8129:
---------------------------------
Pierre,
Another 10% performance improvement is observed after applying your change. The
only problem is binary/string types don't have raw_values() member function.
Disassembled code shows the difference (may be not very accurate as it's hard
to locate the original code after compiler optimization)
{code:c}
*(values_begin + left) < *(values_begin + right);
7b6d29: 49 8b 7c fd 00 mov 0x0(%r13,%rdi,8),%rdi
7b6d2e: 4b 39 7c cd 00 cmp %rdi,0x0(%r13,%r9,8)
{code}
{code:c}
values.GetView(left) < values.GetView(right);
7ba98f: 4c 8b 49 08 mov 0x8(%rcx),%r9
7ba993: 4c 8b 51 20 mov 0x20(%rcx),%r10
7ba997: 4d 8b 49 20 mov 0x20(%r9),%r9
7ba99b: 49 8d 1c da lea (%r10,%rbx,8),%rbx
7ba99f: 49 8d 3c fa lea (%r10,%rdi,8),%rdi
7ba9a3: 4a 8b 3c cf mov (%rdi,%r9,8),%rdi
7ba9a7: 4a 39 3c cb cmp %rdi,(%rbx,%r9,8)
{code}
> [C++][Compute] Refine compare sorting kernel
> --------------------------------------------
>
> Key: ARROW-8129
> URL: https://issues.apache.org/jira/browse/ARROW-8129
> Project: Apache Arrow
> Issue Type: Improvement
> Reporter: Yibo Cai
> Assignee: Yibo Cai
> Priority: Major
>
> Sorting kernel implements two comparison functions,
> [CompareValues|https://github.com/apache/arrow/blob/ab21f0ee429c2a2c82e4dbc5d216ab1da74221a2/cpp/src/arrow/compute/kernels/sort_to_indices.cc#L67]
> use array.Value() for numeric data and
> [CompareViews|https://github.com/apache/arrow/blob/ab21f0ee429c2a2c82e4dbc5d216ab1da74221a2/cpp/src/arrow/compute/kernels/sort_to_indices.cc#L72]
> uses array.GetView() for non-numeric ones. It can be simplified by using
> GetView() only as all data types support GetView().
> To my surprise, benchmark shows about 40% performance improvement after the
> change.
> After some digging, I find in current code, the [comparison
> callback|https://github.com/apache/arrow/blob/ab21f0ee429c2a2c82e4dbc5d216ab1da74221a2/cpp/src/arrow/compute/kernels/sort_to_indices.cc#L94]
> is not inlined (check disassembled code), it leads to a function call. It's
> very bad for this hot loop. Using only GetView() fixes this issue, code
> inlined okay.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)