Skip to content

GH-41035: [C++] Add a grouper benchmark for preventing performance regression - #41036

Merged
pitrou merged 2 commits into
apache:mainfrom
ZhangHuiGui:add-grouper-benchmark
May 21, 2024
Merged

pitrou merged 2 commits into
apache:mainfrom
ZhangHuiGui:add-grouper-benchmark

Conversation

@ZhangHuiGui

@ZhangHuiGui ZhangHuiGui commented Apr 5, 2024 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Add a grouper benchmark for preventing performance regression .

#40998 (comment).

What changes are included in this PR?

Added a benchmark.

Are these changes tested?

Needn't.

Are there any user-facing changes?

No

@github-actions

github-actions Bot commented Apr 5, 2024

Copy link
Copy Markdown

⚠️ GitHub issue #41035 has been automatically assigned in GitHub to PR creator.

@ZhangHuiGui

Copy link
Copy Markdown
Contributor Author

@ursabot please benchmark

@ursabot

ursabot commented Apr 5, 2024

Copy link
Copy Markdown

Benchmark runs are scheduled for commit 620fc87373a76e1805167cb2ed81bb482f10eb1a. Watch https://buildkite.com/apache-arrow and https://conbench.ursa.dev for updates. A comment will be posted here when the runs are complete.

@ZhangHuiGui

Copy link
Copy Markdown
Contributor Author

@pitrou @westonpace PTAL?

@ZhangHuiGui
ZhangHuiGui force-pushed the add-grouper-benchmark branch from 620fc87 to dc0a5b7 Compare April 5, 2024 15:14
@conbench-apache-arrow

Copy link
Copy Markdown

Thanks for your patience. Conbench analyzed the 7 benchmarking runs that have been run so far on PR commit 620fc87373a76e1805167cb2ed81bb482f10eb1a.

There was 1 benchmark result with an error:

There were 4 benchmark results indicating a performance regression:

The full Conbench report has more details.

@ZhangHuiGui
ZhangHuiGui force-pushed the add-grouper-benchmark branch from dc0a5b7 to 001d4c3 Compare April 10, 2024 14:48
@ZhangHuiGui

Copy link
Copy Markdown
Contributor Author

@ursabot please benchmark

@ursabot

ursabot commented Apr 10, 2024

Copy link
Copy Markdown

Benchmark runs are scheduled for commit 001d4c30a2d7d886fa5b452803e8be84efb3f82e. Watch https://buildkite.com/apache-arrow and https://conbench.ursa.dev for updates. A comment will be posted here when the runs are complete.

@conbench-apache-arrow

Copy link
Copy Markdown

Thanks for your patience. Conbench analyzed the 4 benchmarking runs that have been run so far on PR commit 001d4c30a2d7d886fa5b452803e8be84efb3f82e.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool benchmark, nice and concisely written yet covers a wide variety of cases.

One minor nit is that I prefer bytes processed over items processed (it is more comparable and I don't have to worry about knowing as many details of the benchmark) but I won't force that.

Can you share some example results? I see conbench runs but can't find this benchmark in the report (perhaps my mistake on reading the report)

Comment on lines 65 to 81

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Grouper stateless? Would it make more sense to do this in batches?

for (auto _ : state) {
  // Create new grouper
  grouper = ...
  // 256 is just some arbitrary batch size to make sure initialization of the grouper doesn't dominate the benchmark
  for (int i = 0; i < 256; i++) {
    ASSIGN_OR_ABORT(auto group_ids, grouper->Consume(span));
  }
}

Or would it maybe make sense to do one run first to prime the result:

// Prime the grouper
ASSIGN_OR_ABORT(auto init, grouper->Consume(span));
for (auto _ : state) {
  ...

This is only a minor nit, feel free to ignore. In the grand scheme of things, if we are getting enough iterations, this probably doesn't really matter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with this!

@pitrou

pitrou commented Apr 10, 2024

Copy link
Copy Markdown
Member

I would really prefer items/s over bytes/s as bytes/s is highly misleading. In the end, we are most of the time interested in performance over logical items, not in how large the data representation is.

@pitrou

pitrou commented Apr 10, 2024

Copy link
Copy Markdown
Member

(that said, it's not forbidden to add both)

@ZhangHuiGui

ZhangHuiGui commented Apr 11, 2024 •

Copy link
Copy Markdown
Contributor Author

One minor nit is that I prefer bytes processed over items processed (it is more comparable and I don't have to worry about knowing as many details of the benchmark) but I won't force that.

As pitrou said, bytes is actually not accurate in this benchmark because we have a varlength type, which may make the bytes/s indicator very high, but it is not as intuitive as items/s.

The results are like below:

2024-04-11T09:04:45+08:00
Running ./arrow-compute-grouper-benchmark
Run on (16 X 3800 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 512 KiB (x8)
  L3 Unified 16384 KiB (x1)
Load Average: 1.18, 1.64, 1.97
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
***WARNING*** Library was built as DEBUG. Timings may be affected.
---------------------------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                                                         Time             CPU   Iterations UserCounters...
---------------------------------------------------------------------------------------------------------------------------------------------------
GrouperWithMultiTypes/"{boolean}"/1024/10000                                                   1329 us         1329 us          526 items_per_second=770.333k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{boolean}"/1024/100                                                     1508 us         1507 us          465 items_per_second=679.37k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{boolean}"/1024/10                                                      1534 us         1533 us          457 items_per_second=667.84k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{boolean}"/1024/2                                                       1616 us         1616 us          432 items_per_second=633.552k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{boolean}"/1024/1                                                       1720 us         1720 us          405 items_per_second=595.489k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{boolean}"/1024/0                                                       1333 us         1333 us          527 items_per_second=768.172k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{boolean}"/4096/10000                                                   5127 us         5127 us          137 items_per_second=798.951k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{boolean}"/4096/100                                                     5819 us         5818 us          120 items_per_second=703.99k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{boolean}"/4096/10                                                      5877 us         5876 us          118 items_per_second=697.06k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{boolean}"/4096/2                                                       6308 us         6307 us          112 items_per_second=649.449k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{boolean}"/4096/1                                                       6641 us         6640 us          105 items_per_second=616.851k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{boolean}"/4096/0                                                       5121 us         5120 us          136 items_per_second=800.072k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{int32}"/1024/10000                                                     1368 us         1368 us          513 items_per_second=748.798k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{int32}"/1024/100                                                       1620 us         1620 us          432 items_per_second=632.098k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{int32}"/1024/10                                                        1597 us         1597 us          439 items_per_second=641.304k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{int32}"/1024/2                                                         1625 us         1624 us          431 items_per_second=630.423k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{int32}"/1024/1                                                         1637 us         1636 us          428 items_per_second=625.837k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{int32}"/1024/0                                                         1379 us         1378 us          508 items_per_second=743.075k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{int32}"/4096/10000                                                     5402 us         5401 us          130 items_per_second=758.434k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{int32}"/4096/100                                                       6196 us         6195 us          113 items_per_second=661.201k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{int32}"/4096/10                                                        6165 us         6164 us          113 items_per_second=664.549k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{int32}"/4096/2                                                         6300 us         6299 us          111 items_per_second=650.222k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{int32}"/4096/1                                                         6287 us         6286 us          111 items_per_second=651.6k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{int32}"/4096/0                                                         5412 us         5411 us          129 items_per_second=757.029k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{int64}"/1024/10000                                                     1347 us         1347 us          518 items_per_second=760.192k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{int64}"/1024/100                                                       1569 us         1568 us          447 items_per_second=652.955k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{int64}"/1024/10                                                        1577 us         1576 us          444 items_per_second=649.554k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{int64}"/1024/2                                                         1604 us         1604 us          435 items_per_second=638.412k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{int64}"/1024/1                                                         1607 us         1607 us          435 items_per_second=637.123k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{int64}"/1024/0                                                         1374 us         1374 us          522 items_per_second=745.246k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{int64}"/4096/10000                                                     5371 us         5370 us          129 items_per_second=762.703k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{int64}"/4096/100                                                       6181 us         6180 us          113 items_per_second=662.826k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{int64}"/4096/10                                                        6157 us         6156 us          113 items_per_second=665.384k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{int64}"/4096/2                                                         6234 us         6232 us          112 items_per_second=657.237k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{int64}"/4096/1                                                         6251 us         6250 us          113 items_per_second=655.382k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{int64}"/4096/0                                                         5371 us         5370 us          130 items_per_second=762.709k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{utf8}"/1024/10000                                                      2497 us         2496 us          281 items_per_second=410.19k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{utf8}"/1024/100                                                        2694 us         2694 us          260 items_per_second=380.111k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{utf8}"/1024/10                                                         2617 us         2616 us          268 items_per_second=391.371k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{utf8}"/1024/2                                                          2551 us         2551 us          274 items_per_second=401.434k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{utf8}"/1024/1                                                          3188 us         3187 us          220 items_per_second=321.258k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{utf8}"/1024/0                                                          2501 us         2500 us          273 items_per_second=409.55k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{utf8}"/4096/10000                                                     10590 us        10588 us           66 items_per_second=386.85k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{utf8}"/4096/100                                                       10617 us        10615 us           66 items_per_second=385.858k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{utf8}"/4096/10                                                        10379 us        10377 us           67 items_per_second=394.717k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{utf8}"/4096/2                                                         10074 us        10072 us           70 items_per_second=406.684k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{utf8}"/4096/1                                                         12487 us        12485 us           56 items_per_second=328.078k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{utf8}"/4096/0                                                          9820 us         9817 us           71 items_per_second=417.214k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/1024/10000                                    3061 us         3060 us          228 items_per_second=334.659k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/1024/100                                      3316 us         3315 us          209 items_per_second=308.917k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/1024/10                                       3340 us         3339 us          211 items_per_second=306.641k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/1024/2                                        3242 us         3241 us          217 items_per_second=315.953k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/1024/1                                        3157 us         3156 us          221 items_per_second=324.446k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/1024/0                                        3114 us         3114 us          226 items_per_second=328.872k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/4096/10000                                   12839 us        12836 us           55 items_per_second=319.102k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/4096/100                                     13759 us        13755 us           51 items_per_second=297.774k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/4096/10                                      13416 us        13413 us           53 items_per_second=305.371k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/4096/2                                       13103 us        13101 us           54 items_per_second=312.646k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/4096/1                                       12628 us        12626 us           55 items_per_second=324.398k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{fixed_size_binary(128)}"/4096/0                                       12778 us        12775 us           55 items_per_second=320.619k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{boolean, utf8}"/1024/10000                                             3102 us         3102 us          226 items_per_second=330.162k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{boolean, utf8}"/1024/100                                              13830 us        13827 us           51 items_per_second=74.0558k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{boolean, utf8}"/1024/10                                              394675 us       394582 us            2 items_per_second=2.59515k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{boolean, utf8}"/1024/2                                              1409485 us      1409178 us            1 items_per_second=726.665/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{boolean, utf8}"/1024/1                                                 4343 us         4343 us          162 items_per_second=235.808k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{boolean, utf8}"/1024/0                                                 3111 us         3111 us          226 items_per_second=329.148k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{boolean, utf8}"/4096/10000                                            13898 us        13894 us           51 items_per_second=294.793k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{boolean, utf8}"/4096/100                                              54716 us        54700 us           12 items_per_second=74.8806k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{boolean, utf8}"/4096/10                                              941758 us       941554 us            1 items_per_second=4.35026k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{boolean, utf8}"/4096/2                                             12871536 us     12868926 us            1 items_per_second=318.286/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{boolean, utf8}"/4096/1                                                16971 us        16968 us           41 items_per_second=241.392k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{boolean, utf8}"/4096/0                                                12383 us        12381 us           56 items_per_second=330.834k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{int32, int32}"/1024/10000                                              1635 us         1634 us          428 items_per_second=626.497k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{int32, int32}"/1024/100                                                2020 us         2019 us          344 items_per_second=507.07k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{int32, int32}"/1024/10                                                 2114 us         2114 us          331 items_per_second=484.407k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{int32, int32}"/1024/2                                                  2318 us         2317 us          303 items_per_second=441.867k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{int32, int32}"/1024/1                                                  2499 us         2498 us          280 items_per_second=409.852k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{int32, int32}"/1024/0                                                  1636 us         1636 us          420 items_per_second=625.86k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{int32, int32}"/4096/10000                                              6523 us         6522 us          108 items_per_second=628.047k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{int32, int32}"/4096/100                                                8122 us         8120 us           86 items_per_second=504.427k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{int32, int32}"/4096/10                                                 8473 us         8472 us           83 items_per_second=483.476k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{int32, int32}"/4096/2                                                  9209 us         9207 us           76 items_per_second=444.856k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{int32, int32}"/4096/1                                                  9863 us         9861 us           70 items_per_second=415.358k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{int32, int32}"/4096/0                                                  6532 us         6531 us          107 items_per_second=627.155k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{int32, int64}"/1024/10000                                              1628 us         1628 us          431 items_per_second=629.181k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{int32, int64}"/1024/100                                               12616 us        12614 us           55 items_per_second=81.1817k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{int32, int64}"/1024/10                                                89235 us        89216 us            8 items_per_second=11.4778k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{int32, int64}"/1024/2                                                279436 us       279381 us            2 items_per_second=3.66524k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{int32, int64}"/1024/1                                                  2474 us         2473 us          283 items_per_second=413.992k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{int32, int64}"/1024/0                                                  1627 us         1627 us          429 items_per_second=629.503k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{int32, int64}"/4096/10000                                              6484 us         6483 us          107 items_per_second=631.833k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{int32, int64}"/4096/100                                               49194 us        49186 us           14 items_per_second=83.2752k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{int32, int64}"/4096/10                                               414187 us       414110 us            2 items_per_second=9.89109k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{int32, int64}"/4096/2                                               1350538 us      1350126 us            1 items_per_second=3.03379k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{int32, int64}"/4096/1                                                  9590 us         9588 us           73 items_per_second=427.195k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{int32, int64}"/4096/0                                                  6475 us         6474 us          108 items_per_second=632.68k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/1024/10000                                      3679 us         3678 us          190 items_per_second=278.42k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/1024/100                                       17617 us        17614 us           40 items_per_second=58.1361k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/1024/10                                       191058 us       191017 us            4 items_per_second=5.36077k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/1024/2                                        718916 us       718763 us            1 items_per_second=1.42467k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/1024/1                                          5451 us         5450 us          129 items_per_second=187.874k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/1024/0                                          3675 us         3675 us          190 items_per_second=278.664k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/4096/10000                                     17341 us        17338 us           41 items_per_second=236.242k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/4096/100                                      100409 us       100389 us            7 items_per_second=40.8013k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/4096/10                                       921094 us       920851 us            1 items_per_second=4.44806k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/4096/2                                       3632795 us      3631833 us            1 items_per_second=1.12781k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/4096/1                                         21414 us        21411 us           33 items_per_second=191.299k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{boolean, int64, utf8}"/4096/0                                         14967 us        14965 us           46 items_per_second=273.711k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/10000                                      3724 us         3724 us          188 items_per_second=275.008k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/100                                       13209 us        13207 us           53 items_per_second=77.5372k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/10                                       140985 us       140961 us            5 items_per_second=7.26443k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/2                                        500871 us       500788 us            2 items_per_second=2.04478k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/1                                          5491 us         5490 us          128 items_per_second=186.517k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/0                                          3724 us         3723 us          188 items_per_second=275.053k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/10000                                     17473 us        17469 us           40 items_per_second=234.471k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/100                                       73179 us        73165 us            9 items_per_second=55.9829k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/10                                       602449 us       602346 us            1 items_per_second=6.80008k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/2                                       4447236 us      4446227 us            1 items_per_second=921.231/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/1                                         21541 us        21538 us           32 items_per_second=190.176k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/0                                         15239 us        15236 us           46 items_per_second=268.834k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/10000                               4207 us         4207 us          166 items_per_second=243.428k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/100                                35682 us        35671 us           20 items_per_second=28.7065k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/10                                280647 us       280589 us            2 items_per_second=3.64946k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/2                                 739914 us       739742 us            1 items_per_second=1.38427k/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/1                                   6503 us         6502 us          107 items_per_second=157.495k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/0                                   4218 us         4218 us          166 items_per_second=242.792k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/10000                              17237 us        17233 us           40 items_per_second=237.677k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/100                               153723 us       153695 us            5 items_per_second=26.6501k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/10                               1299692 us      1299383 us            1 items_per_second=3.15227k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/2                                3874521 us      3873499 us            1 items_per_second=1.05744k/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/1                                  25555 us        25551 us           27 items_per_second=160.306k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/0                                  17337 us        17332 us           41 items_per_second=236.323k/s null_percent=0 size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/10000       6799 us         6798 us          104 items_per_second=150.63k/s null_percent=0.01 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/100        45711 us        45700 us           15 items_per_second=22.4068k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/10        445610 us       445504 us            2 items_per_second=2.29852k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/2        1191552 us      1191089 us            1 items_per_second=859.718/s null_percent=50 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/1           9183 us         9182 us           75 items_per_second=111.529k/s null_percent=100 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/0           6818 us         6816 us          104 items_per_second=150.231k/s null_percent=0 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/10000      31751 us        31744 us           22 items_per_second=129.033k/s null_percent=0.01 size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/100       224880 us       224830 us            3 items_per_second=18.2182k/s null_percent=1 size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/10       2333998 us      2332975 us            1 items_per_second=1.7557k/s null_percent=10 size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/2        5439532 us      5437715 us            1 items_per_second=753.258/s null_percent=50 size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/1          36049 us        36043 us           19 items_per_second=113.64k/s null_percent=100 size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/0          27792 us        27785 us           25 items_per_second=147.415k/s null_percent=0 size=4.096k

@ZhangHuiGui
ZhangHuiGui force-pushed the add-grouper-benchmark branch from 001d4c3 to ec199fa Compare April 11, 2024 01:09

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @ZhangHuiGui . I wonder if these benchmarks are realistic, because it seems that in most cases (except boolean), the input keys will be mostly unique?

Comment thread cpp/src/arrow/compute/CMakeLists.txt Outdated

@pitrou pitrou Apr 11, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this into row/CMakeLists.txt?

@pitrou pitrou Apr 11, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a third-party include, could you please move it above and use brackets (#include <benchmark/benchmark.h>)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't make true_probability the same as null_probability (as it makes the data trivial if null_probability is either 0.0 or 1.0), how about a hardcoded value such as 0.2?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, 0.2 is enough for the current situation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's gonna produce a lot of different groups if there's a string key, right? Is it realistic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This benchmark is mainly to ensure that the construction of our underlying RowTable and the performance of the comparison operations in the lower-level compare_internal can be tracked (we have not systematically tested these underlying operations before). It mainly covers some basics. Type, including the impact of null ratio on performance (comparison operations will compare null values separately.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but do we not want the workload to be more realistic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this is indeed a bit unrealistic. Can we use 0.1/0.2 to reduce the proportion of unique?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be better IMHO.
You may also add a comment explaining why you want to test with a large-ish number of groups.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also add a comment explaining why you want to test with a large-ish number of groups.

Agree

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both scenarios have use cases. GroupBy/HashJoin are sometimes used for deduplication and in that use case the key is mostly unique (in fact, we hit bugs in our hash-join impl when users tried this case).

That being said, I agree the "few groups" case is much more common.

@ZhangHuiGui ZhangHuiGui Apr 11, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, it seems that we can also enable swiss_join with the are_cols_in_encoding_order=true option, which can improve the performance of comparison when hashkey-cols need to be resorted.
Of course, this requires some changes to SwissTableWithKeys::Input.

Status status = ColumnArraysFromExecBatch(
batch, begin_row_id, end_row_id - begin_row_id, &temp_column_arrays);
ARROW_DCHECK(status.ok());
LightContext ctx;
ctx.hardware_flags = hardware_flags;
ctx.stack = temp_stack;
KeyCompare::CompareColumnsToRows(
num_selected, batch_selection_maybe_null, array_row_ids, &ctx, out_num_not_equal,
out_not_equal_selection, temp_column_arrays, rows_,
/*are_cols_in_encoding_order=*/false, out_match_bitvector_maybe_null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both scenarios have use cases. GroupBy/HashJoin are sometimes used for deduplication and in that use case the key is mostly unique (in fact, we hit bugs in our hash-join impl when users tried this case).

I see, thanks. Can we clearly mark both kinds of scenarios in the benchmarks? (either as comments in the source code or by using different names for the benchmarks)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comments on Unique's impact scenarios in the benchmark.

But I think there is no need to add an independent benchmark for this. If the data set is all unique and there are non-performance bugs, this matter should be handled by a UT?

This Benchmark should focus on the impact of combining different data types and column rearrangements that occur in RowTable on comparison performance?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, int32 and int64 keys will span the whole magnitude as well? Meaning they will be mostly unique?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we hope that there are enough groups so that we can generate as many comparison operations as possible, which can verify that our underlying comparison performance is stable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 128 bytes a frequent size for fixed_size_binary? Intuitively, I would have guessed much shorter sizes are more common, e.g. 16, 20 or 32 (for decimals, uuids or sha160s, for example).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, 16 seems enough!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "resorted" mean here? Do you mean the columns are in a different order?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in RowTableMetadata::FromColumnMetadataVector when we construct a RowTable.

std::sort(
column_order.begin(), column_order.end(), [&cols](uint32_t left, uint32_t right) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I had no idea the grouper could do this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: the ordering is defined here: https://github.com/apache/arrow/blob/main/cpp/src/arrow/compute/row/row_internal.cc#L65

I'll admit that I don't really understand how that makes things faster but it does, as shown in the comment that inspired this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to dig deeper into the root causes of performance improvement. :) It seems to be beyond expectations.

@ZhangHuiGui ZhangHuiGui Apr 13, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to num_groups in the benchmark, I discovered a very interesting performance phenomenon. When setting are_cols_in_encoding_order in KeyCompare::CompareColumnsToRows in Grouper to false, using the same way of generating data sets we will Generate much more groups, and the performance with a larger number of groups will obviously be worse (because the grouper needs to build and find swisstable).

So the essence of the final performance problem is: Why does the number of groupings in the same data set increase significantly after resort column? Further analysis is needed.

# origin-order, produce much more groups than resorted order
GrouperWithMultiTypes/"{int32, int64}"/8388608/0   45000851 us     44976124 us            1 items_per_second=186.512k/s null_percent=0 num_groups=134.218M size=8.38861M uniqueness=1
GrouperWithMultiTypes/"{int32, int64}"/8388608/0   43829079 us     43799112 us            1 items_per_second=191.525k/s null_percent=0 num_groups=134.218M size=8.38861M uniqueness=1

# resorted order
GrouperWithMultiTypes/"{int64, int32}"/8388608/0    4955565 us      4952519 us            1 items_per_second=1.69381M/s null_percent=0 num_groups=8.38861M size=8.38861M uniqueness=0.0625
GrouperWithMultiTypes/"{int64, int32}"/8388608/0    5004994 us      5001648 us            1 items_per_second=1.67717M/s null_percent=0 num_groups=8.38861M size=8.38861M uniqueness=0.0625

Besides, i've checked the compare logic of these two scenes, the internal logic of their compare is basically the same.

more groups
image-20240413124010435

less groups
image-20240413124309641

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's bug in grouper when set are_cols_in_encoding_order=false in below codes:

/* are_cols_in_encoding_order=*/true);

It will cause the num_group different with are_cols_in_encoding_order=true condition.

The encoder will sort columns by default, when we only set this compare args to false, the CompareColumnsToRows's input impl_ptr->encoder_.batch_all_cols(), impl_ptr->rows_, are all sorted, but use the incorrect column_offset to access compared column:

uint32_t offset_within_row = rows.metadata().encoded_field_offset(
are_cols_in_encoding_order
? static_cast<uint32_t>(icol)
: rows.metadata().pos_after_encoding(static_cast<uint32_t>(icol)));

After simple fix the grouper's are_cols_in_encoding_order=false bug( by add are_cols_sorted into KeyColumnMetadata) i find that the performance almost same with are_cols_in_encoding_order=true.

And also, the purpose of the column-sort in RowTableEncoder is construct an aligned friendly condition for memory access. Resorted order will be used to produce an aligned column_offset for access the row data in encode/decode/compare.

@ZhangHuiGui ZhangHuiGui Apr 16, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After i fix the bug of are_cols_in_encoding_order=false in grouper. Performance like below:

are_cols_in_encoding_order=false

GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/10000                                       288 us          288 us         2472 items_per_second=3.55257M/s null_percent=0.01 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/100                                         332 us          331 us         2132 items_per_second=3.08928M/s null_percent=1 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/10                                          329 us          329 us         2153 items_per_second=3.11651M/s null_percent=10 num_groups=1.009k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/2                                           324 us          324 us         2148 items_per_second=3.16498M/s null_percent=50 num_groups=730 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/1                                           359 us          359 us         1948 items_per_second=2.85145M/s null_percent=100 num_groups=1 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/0                                           286 us          286 us         2413 items_per_second=3.57668M/s null_percent=0 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/10000                                      1282 us         1282 us          541 items_per_second=3.19499M/s null_percent=0.01 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/100                                        1334 us         1334 us          522 items_per_second=3.07032M/s null_percent=1 num_groups=4.092k size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/10                                         1330 us         1329 us          514 items_per_second=3.08117M/s null_percent=10 num_groups=3.999k size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/2                                          1385 us         1385 us          502 items_per_second=2.95787M/s null_percent=50 num_groups=2.779k size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/1                                          1400 us         1400 us          501 items_per_second=2.92583M/s null_percent=100 num_groups=1 size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/0                                          1152 us         1152 us          601 items_per_second=3.55699M/s null_percent=0 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/10000                                330 us          330 us         2081 items_per_second=3.10442M/s null_percent=0.01 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/100                                  395 us          395 us         1810 items_per_second=2.5926M/s null_percent=1 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/10                                   395 us          395 us         1771 items_per_second=2.59343M/s null_percent=10 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/2                                    394 us          394 us         1782 items_per_second=2.59703M/s null_percent=50 num_groups=887 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/1                                    422 us          422 us         1657 items_per_second=2.42852M/s null_percent=100 num_groups=1 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/0                                    320 us          320 us         2170 items_per_second=3.20108M/s null_percent=0 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/10000                               1344 us         1344 us          516 items_per_second=3.04771M/s null_percent=0.01 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/100                                 1576 us         1576 us          446 items_per_second=2.59919M/s null_percent=1 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/10                                  1650 us         1650 us          431 items_per_second=2.48289M/s null_percent=10 num_groups=4.091k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/2                                   1751 us         1751 us          418 items_per_second=2.33929M/s null_percent=50 num_groups=3.484k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/1                                   1651 us         1651 us          424 items_per_second=2.48122M/s null_percent=100 num_groups=1 size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/0                                   1369 us         1369 us          523 items_per_second=2.99227M/s null_percent=0 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/10000        608 us          608 us         1149 items_per_second=1.68426M/s null_percent=0.01 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/100          688 us          688 us         1191 items_per_second=1.48927M/s null_percent=1 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/10           688 us          688 us         1005 items_per_second=1.48878M/s null_percent=10 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/2            738 us          738 us          969 items_per_second=1.38746M/s null_percent=50 num_groups=965 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/1            568 us          568 us         1237 items_per_second=1.80246M/s null_percent=100 num_groups=1 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/0            615 us          615 us         1198 items_per_second=1.66566M/s null_percent=0 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/10000       2838 us         2837 us          248 items_per_second=1.44393M/s null_percent=0.01 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/100         2942 us         2941 us          236 items_per_second=1.39289M/s null_percent=1 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/10          3018 us         3017 us          235 items_per_second=1.3578M/s null_percent=10 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/2           3151 us         3150 us          224 items_per_second=1.3002M/s null_percent=50 num_groups=3.828k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/1           2271 us         2270 us          299 items_per_second=1.80433M/s null_percent=100 num_groups=1 size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/0           2663 us         2662 us          270 items_per_second=1.53886M/s null_percent=0 num_groups=4.096k size=4.096k

are_cols_in_encoding_order=true

GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/10000                                       290 us          290 us         2469 items_per_second=3.52659M/s null_percent=0.01 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/100                                         418 us          418 us         1702 items_per_second=2.44793M/s null_percent=1 num_groups=1.27k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/10                                          920 us          920 us          731 items_per_second=1.11333M/s null_percent=10 num_groups=3.598k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/2                                          4423 us         4422 us          158 items_per_second=231.569k/s null_percent=50 num_groups=6.386k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/1                                           367 us          367 us         1946 items_per_second=2.79268M/s null_percent=100 num_groups=1 size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/0                                           279 us          279 us         2497 items_per_second=3.66686M/s null_percent=0 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/10000                                      1233 us         1233 us          560 items_per_second=3.32317M/s null_percent=0.01 num_groups=4.098k size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/100                                        1642 us         1642 us          415 items_per_second=2.49463M/s null_percent=1 num_groups=4.971k size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/10                                         4417 us         4415 us          158 items_per_second=927.686k/s null_percent=10 num_groups=14.036k size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/2                                         35053 us        35045 us           20 items_per_second=116.878k/s null_percent=50 num_groups=25.076k size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/1                                          1399 us         1399 us          501 items_per_second=2.92779M/s null_percent=100 num_groups=1 size=4.096k
GrouperWithMultiTypes/"{int32, boolean, utf8}"/4096/0                                          1100 us         1100 us          613 items_per_second=3.72269M/s null_percent=0 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/10000                                314 us          314 us         2263 items_per_second=3.25722M/s null_percent=0.01 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/100                                  506 us          506 us         1372 items_per_second=2.02275M/s null_percent=1 num_groups=1.63k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/10                                  1515 us         1514 us          466 items_per_second=676.307k/s null_percent=10 num_groups=5.674k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/2                                   4296 us         4295 us          163 items_per_second=238.424k/s null_percent=50 num_groups=11.405k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/1                                    432 us          432 us         1655 items_per_second=2.37068M/s null_percent=100 num_groups=1 size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/1024/0                                    311 us          311 us         2239 items_per_second=3.2934M/s null_percent=0 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/10000                               1265 us         1264 us          551 items_per_second=3.23969M/s null_percent=0.01 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/100                                 2216 us         2216 us          319 items_per_second=1.84872M/s null_percent=1 num_groups=6.139k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/10                                  7549 us         7547 us           91 items_per_second=542.731k/s null_percent=10 num_groups=22.322k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/2                                  23964 us        23956 us           29 items_per_second=170.979k/s null_percent=50 num_groups=44.868k size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/1                                   1663 us         1663 us          423 items_per_second=2.46312M/s null_percent=100 num_groups=1 size=4.096k
GrouperWithMultiTypes/"{int32, int64, boolean, utf8}"/4096/0                                   1271 us         1271 us          549 items_per_second=3.22388M/s null_percent=0 num_groups=4.096k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/10000        495 us          495 us         1389 items_per_second=2.06983M/s null_percent=0.01 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/100          802 us          802 us          883 items_per_second=1.27742M/s null_percent=1 num_groups=1.622k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/10          2523 us         2522 us          281 items_per_second=405.964k/s null_percent=10 num_groups=6.011k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/2           6945 us         6942 us          110 items_per_second=147.514k/s null_percent=50 num_groups=11.936k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/1            626 us          626 us          933 items_per_second=1.63646M/s null_percent=100 num_groups=1 size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/1024/0            513 us          513 us         1392 items_per_second=1.99517M/s null_percent=0 num_groups=1.024k size=1.024k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/10000       2359 us         2359 us          294 items_per_second=1.73639M/s null_percent=0.01 num_groups=4.1k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/100         3889 us         3888 us          178 items_per_second=1.05341M/s null_percent=1 num_groups=6.219k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/10         13720 us        13715 us           50 items_per_second=298.661k/s null_percent=10 num_groups=24k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/2          26470 us        26462 us           24 items_per_second=154.787k/s null_percent=50 num_groups=48.565k size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/1           2322 us         2322 us          302 items_per_second=1.7641M/s null_percent=100 num_groups=1 size=4.096k
GrouperWithMultiTypes/"{utf8, int32, int64, fixed_size_binary(128), boolean}"/4096/0           2070 us         2069 us          340 items_per_second=1.97969M/s null_percent=0 num_groups=4.096k size=4.096k

And there is a bug which would cause compare null with a wrong result #40998 hasn't merged. So some of num_groups are wrong when are_cols_in_encoding_order=true.
like:

# are_cols_in_encoding_order=false
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/2                                           324 us          324 us         2148 items_per_second=3.16498M/s null_percent=50 num_groups=730 size=1.024k

# are_cols_in_encoding_order=true
GrouperWithMultiTypes/"{int32, boolean, utf8}"/1024/2                                          4423 us         4422 us          158 items_per_second=231.569k/s null_percent=50 num_groups=6.386k size=1.024k

Comment on lines 66 to 83

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be informative to output the number of distinct groups here. Something like:

Suggested change
for (auto _ : state) {
ASSIGN_OR_ABORT(auto grouper, Grouper::Make(span.GetTypes(), ctx));
for (int i = 0; i < kRound; ++i) {
ASSIGN_OR_ABORT(auto group_ids, grouper->Consume(span));
}
}
state.SetItemsProcessed(state.iterations() * kRound * span.length);
uint32_t num_groups = 0;
for (auto _ : state) {
ASSIGN_OR_ABORT(auto grouper, Grouper::Make(span.GetTypes(), ctx));
for (int i = 0; i < kRound; ++i) {
ASSIGN_OR_ABORT(auto group_ids, grouper->Consume(span));
}
num_groups = grouper->num_groups();
}
state.SetItemsProcessed(state.iterations() * kRound * span.length);
state.counters["num_groups"] = num_groups;
state.counters["uniqueness"] = static_cast<double>(num_groups) / (kRound * span.length);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that some of the benchmark variations seem quite slow, we should reduce this to a smaller value, such as 16 perhaps.

@pitrou

pitrou commented Apr 11, 2024

Copy link
Copy Markdown
Member

I find it interesting that some benchmark variations fall to abysmal speeds, for example for {int32, int64}:

GrouperWithMultiTypes/"{int32, int64}"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/1024/100                                               12616 us        12614 us           55 items_per_second=81.1817k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{int32, int64}"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/1024/10                                                89235 us        89216 us            8 items_per_second=11.4778k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{int32, int64}"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/1024/2                                                279436 us       279381 us            2 items_per_second=3.66524k/s null_percent=50 size=1.024k

but not the same benchmark for {int32, int32}:

GrouperWithMultiTypes/"{int32, int32}"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/1024/100                                                2020 us         2019 us          344 items_per_second=507.07k/s null_percent=1 size=1.024k
GrouperWithMultiTypes/"{int32, int32}"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/1024/10                                                 2114 us         2114 us          331 items_per_second=484.407k/s null_percent=10 size=1.024k
GrouperWithMultiTypes/"{int32, int32}"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/1024/2                                                  2318 us         2317 us          303 items_per_second=441.867k/s null_percent=50 size=1.024k

@ZhangHuiGui

Copy link
Copy Markdown
Contributor Author
024/2                                                279436 us

Ah, nice catch.
The performance problem here should be due to two reasons:

  1. A random null ratio of more than 50% will increase the cost of comparison. CompareColumnsToRows requires more branches to participate.
    // Version without using selection vector
    CompareBinaryColumnToRow<false>(
    offset_within_row, num_rows_to_compare, sel_left_maybe_null,
    left_to_right_map, ctx, col, rows,
    is_first_column ? match_bytevector_A : match_bytevector_B);
    NullUpdateColumnToRow<false>(
    static_cast<uint32_t>(icol), num_rows_to_compare, sel_left_maybe_null,
    left_to_right_map, ctx, col, rows,
    is_first_column ? match_bytevector_A : match_bytevector_B,
    are_cols_in_encoding_order);
  2. The reason why the performance of int32+int64 is much worse than that of int32+int32 is because the different col_width of each row needs to enter different branches during the comparison process, which will destroy the CPU pipeline.

} else if (col_width == 4) {
CompareBinaryColumnToRowHelper<use_selection>(
offset_within_row, num_processed, num_rows_to_compare, sel_left_maybe_null,
left_to_right_map, ctx, col, rows, match_bytevector,
[](const uint8_t* left_base, const uint8_t* right_base, uint32_t irow_left,
uint32_t offset_right) {
util::CheckAlignment<uint32_t>(left_base);
util::CheckAlignment<uint32_t>(right_base + offset_right);
uint32_t left = reinterpret_cast<const uint32_t*>(left_base)[irow_left];
uint32_t right = *reinterpret_cast<const uint32_t*>(right_base + offset_right);
return left == right ? 0xff : 0;
});
} else if (col_width == 8) {
CompareBinaryColumnToRowHelper<use_selection>(
offset_within_row, num_processed, num_rows_to_compare, sel_left_maybe_null,
left_to_right_map, ctx, col, rows, match_bytevector,
[](const uint8_t* left_base, const uint8_t* right_base, uint32_t irow_left,
uint32_t offset_right) {
util::CheckAlignment<uint64_t>(left_base);
util::CheckAlignment<uint64_t>(right_base + offset_right);
uint64_t left = reinterpret_cast<const uint64_t*>(left_base)[irow_left];
uint64_t right = *reinterpret_cast<const uint64_t*>(right_base + offset_right);
return left == right ? 0xff : 0;
});

@pitrou

pitrou commented May 6, 2024

Copy link
Copy Markdown
Member

@ZhangHuiGui I have lost track of what this PR's status is. Does it need to wait for other PRs? Do you intend to bring further changes to it?

@ZhangHuiGui

Copy link
Copy Markdown
Contributor Author

@ZhangHuiGui I have lost track of what this PR's status is. Does it need to wait for other PRs? Do you intend to bring further changes to it?

This PR is mainly used for Grouper performance testing and is relatively independent. A performance problem previously discovered(#41233) through this test will be fixed in other PRs. I think there is nothing that needs to be added in this PR.

@ZhangHuiGui

Copy link
Copy Markdown
Contributor Author

@pitrou It looks like this PR can move forward?

@pitrou
pitrou force-pushed the add-grouper-benchmark branch from aaf8dcc to 14cbc5f Compare May 21, 2024 14:02

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @ZhangHuiGui

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit 28ab4af.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 5 possible false positives for unstable benchmarks that are known to sometimes produce them.

vibhatha pushed a commit to vibhatha/arrow that referenced this pull request May 25, 2024
…nce regression (apache#41036)

### Rationale for this change
Add a grouper benchmark for preventing performance regression . 

apache#40998 (comment).

### What changes are included in this PR?
Added a benchmark.

### Are these changes tested?
Needn't.

### Are there any user-facing changes?
No

* GitHub Issue: apache#41035

Authored-by: ZhangHuiGui <hugo.zhang@openpie.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
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.

4 participants