Skip to content
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

[Enhancement] Use nibble mask in filter_range for ARM #44194

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

ZiheLiu
Copy link
Contributor

@ZiheLiu ZiheLiu commented Apr 16, 2024

Why I'm doing:

Optimize filter_range for ARM.

Here is the CPU perf flame graph for the SSB 100GB Q07. The occupation of FixedLengthColumnBase<int>::filter_range increases from 11.35% on x86 to 19.27% on ARM.

Q07 is special, because almost every chunk keeps several rows after filtering. Therefore, the third branch always hit by every chunk.

           if (vmaxvq_u8(filter) == 0) {
                // skip
            } else if (vminvq_u8(filter)) {
                memmove(data + result_offset, data + start_offset, kBatchNums * data_type_size);
                result_offset += kBatchNums;
            } else { /* --------- the third branch --------- */
                for (int i = 0; i < kBatchNums; ++i) {
                    if (vgetq_lane_u8(filter, i)) {
                        *(data + result_offset++) = *(data + start_offset + i);
                    }
                }
            }

on ARM
Q07 perf arm

on x86
Q07 perf x86

What I'm doing:

Inspired by this article, we could get a nibble mask for the filter result, which is a 64-bit mask, each 4-bit represents a byte of the input.

And then we could use x &= (x - 1) and __builtin_ctzll to iterate through bits to eliminate if branch, which referred to as Kernighan's algorithm.

Test

Enviroment

Test Result

  • Q07
    • Before: 568ms
    • After: 487ms
  • Q11
    • Before: 612ms
    • After: 554ms

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
@ZiheLiu ZiheLiu requested review from a team as code owners April 16, 2024 12:43
Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@stdpain stdpain merged commit 6326aa0 into StarRocks:main Apr 17, 2024
81 checks passed
leiyang0324 pushed a commit to leiyang0324/starrocks that referenced this pull request Apr 19, 2024
ZiheLiu added a commit to ZiheLiu/starrocks that referenced this pull request Apr 25, 2024
Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
@ZiheLiu
Copy link
Contributor Author

ZiheLiu commented Apr 26, 2024

@mergify backport branch-3.2 branch-3.3

Copy link
Contributor

mergify bot commented Apr 26, 2024

backport branch-3.2 branch-3.3

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Apr 26, 2024
Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
(cherry picked from commit 6326aa0)
mergify bot pushed a commit that referenced this pull request Apr 26, 2024
Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
(cherry picked from commit 6326aa0)
wanpengfei-git pushed a commit that referenced this pull request Apr 26, 2024
… (#44818)

Co-authored-by: zihe.liu <ziheliu1024@gmail.com>
kangkaisen pushed a commit that referenced this pull request Apr 26, 2024
… (#44819)

Co-authored-by: zihe.liu <ziheliu1024@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants