Skip to content

Replace BufferBuilder with Vec in sort_run_downcasted - #10630

Open
cakeni wants to merge 1 commit into
apache:mainfrom
cakeni:perf/arrow-ord-sort-run-ends-vec
Open

Replace BufferBuilder with Vec in sort_run_downcasted#10630
cakeni wants to merge 1 commit into
apache:mainfrom
cakeni:perf/arrow-ord-sort-run-ends-vec

Conversation

@cakeni

@cakeni cakeni commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Using Vec instead of BufferBuilder can benefit from Rust's optimized vector implementation. This updates the remaining BufferBuilder usage in arrow-ord/src/sort.rs.

What changes are included in this PR?

  • Replace the run-end BufferBuilder in sort_run_downcasted with a preallocated Vec.
  • Push converted run ends directly into the vector and convert it into the final Arrow buffer.

Are these changes tested?

Yes. The following checks pass:

  • cargo +stable-x86_64-pc-windows-gnu fmt --all -- --check
  • cargo +stable-x86_64-pc-windows-gnu clippy -p arrow-ord --all-targets --all-features --no-deps -- -D warnings
  • cargo +stable-x86_64-pc-windows-gnu test -p arrow-ord --all-features (269 unit tests and 6 doctests passed)

Are there any user-facing changes?

No.

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-ord labels Aug 11, 2026

@Rich-T-kid Rich-T-kid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@Jefffrey

Copy link
Copy Markdown
Contributor

run benchmark sort_kernel

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c5263928681-1557-bpcfx 6.12.85+ #1 SMP Wed Jun 17 20:31:55 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing perf/arrow-ord-sort-run-ends-vec (c46c18e) to fc16607 (merge-base) diff

Run configuration
run benchmark sort_kernel

BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench sort_kernel
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

Comparing perf/arrow-ord-sort-run-ends-vec (c46c18e) to fc16607 (merge-base) diff

Run configuration
run benchmark sort_kernel
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                                   main                                   perf_arrow-ord-sort-run-ends-vec
-----                                                   ----                                   --------------------------------
lexsort (bool, bool) 2^12                               1.00     78.9±0.65µs        ? ?/sec    1.01     79.7±0.46µs        ? ?/sec
lexsort (bool, bool) nulls 2^12                         1.00     90.8±0.11µs        ? ?/sec    1.00     90.7±0.21µs        ? ?/sec
lexsort (f32, f32) 2^10                                 1.00     31.4±0.14µs        ? ?/sec    1.00     31.2±0.12µs        ? ?/sec
lexsort (f32, f32) 2^12                                 1.00    250.7±0.83µs        ? ?/sec    1.00    249.8±0.66µs        ? ?/sec
lexsort (f32, f32) 2^12 limit 10                        1.00      9.8±0.01µs        ? ?/sec    1.00      9.8±0.01µs        ? ?/sec
lexsort (f32, f32) 2^12 limit 100                       1.00     19.0±0.02µs        ? ?/sec    1.01     19.1±0.04µs        ? ?/sec
lexsort (f32, f32) 2^12 limit 1000                      1.01     77.6±0.29µs        ? ?/sec    1.00     76.7±0.31µs        ? ?/sec
lexsort (f32, f32) 2^12 limit 2^12                      1.00    250.6±0.55µs        ? ?/sec    1.00    250.4±1.70µs        ? ?/sec
lexsort (f32, f32) nulls 2^10                           1.00     33.1±0.04µs        ? ?/sec    1.01     33.4±0.31µs        ? ?/sec
lexsort (f32, f32) nulls 2^12                           1.09    190.3±0.79µs        ? ?/sec    1.00    174.5±0.37µs        ? ?/sec
lexsort (f32, f32) nulls 2^12 limit 10                  1.00     15.5±0.16µs        ? ?/sec    1.03     16.0±0.48µs        ? ?/sec
lexsort (f32, f32) nulls 2^12 limit 100                 1.00     18.4±0.17µs        ? ?/sec    1.03     19.0±0.56µs        ? ?/sec
lexsort (f32, f32) nulls 2^12 limit 1000                1.00     48.8±0.13µs        ? ?/sec    1.00     48.7±0.10µs        ? ?/sec
lexsort (f32, f32) nulls 2^12 limit 2^12                1.09    190.3±0.49µs        ? ?/sec    1.00    174.4±0.35µs        ? ?/sec
rank f32 2^12                                           1.00     47.1±0.04µs        ? ?/sec    1.00     47.1±0.04µs        ? ?/sec
rank f32 nulls 2^12                                     1.00     23.6±0.03µs        ? ?/sec    1.00     23.6±0.02µs        ? ?/sec
rank string[10] 2^12                                    1.02    163.9±0.18µs        ? ?/sec    1.00    160.1±0.36µs        ? ?/sec
rank string[10] nulls 2^12                              1.00     75.8±0.07µs        ? ?/sec    1.00     75.6±0.11µs        ? ?/sec
rank string_view[0-400] 2^12                            1.06    188.5±0.54µs        ? ?/sec    1.00    178.6±0.56µs        ? ?/sec
rank string_view[0-400] nulls 2^12                      1.02     78.2±0.23µs        ? ?/sec    1.00     76.6±0.17µs        ? ?/sec
rank string_view[10] 2^12                               1.03    163.7±0.34µs        ? ?/sec    1.00    159.1±0.17µs        ? ?/sec
rank string_view[10] nulls 2^12                         1.01     76.1±0.14µs        ? ?/sec    1.00     75.1±0.18µs        ? ?/sec
sort f32 2^12                                           1.00     42.7±0.02µs        ? ?/sec    1.00     42.7±0.02µs        ? ?/sec
sort f32 nulls 2^12                                     1.00     21.6±0.01µs        ? ?/sec    1.00     21.7±0.01µs        ? ?/sec
sort f32 nulls to indices 2^12                          1.00     26.4±0.03µs        ? ?/sec    1.00     26.5±0.03µs        ? ?/sec
sort f32 to indices 2^12                                1.00     50.6±0.03µs        ? ?/sec    1.00     50.6±0.04µs        ? ?/sec
sort i32 2^10                                           1.00      6.4±0.00µs        ? ?/sec    1.00      6.4±0.01µs        ? ?/sec
sort i32 2^12                                           1.00     31.9±0.03µs        ? ?/sec    1.00     32.1±0.02µs        ? ?/sec
sort i32 nulls 2^10                                     1.00      3.8±0.01µs        ? ?/sec    1.00      3.8±0.01µs        ? ?/sec
sort i32 nulls 2^12                                     1.00     16.4±0.01µs        ? ?/sec    1.01     16.4±0.02µs        ? ?/sec
sort i32 nulls to indices 2^10                          1.00      5.5±0.01µs        ? ?/sec    1.00      5.5±0.01µs        ? ?/sec
sort i32 nulls to indices 2^12                          1.00     23.4±0.03µs        ? ?/sec    1.00     23.4±0.03µs        ? ?/sec
sort i32 to indices 2^10                                1.00      9.6±0.01µs        ? ?/sec    1.00      9.6±0.01µs        ? ?/sec
sort i32 to indices 2^12                                1.00     44.1±0.09µs        ? ?/sec    1.00     44.1±0.05µs        ? ?/sec
sort primitive run 2^12                                 1.03      5.2±0.01µs        ? ?/sec    1.00      5.1±0.01µs        ? ?/sec
sort primitive run to indices 2^12                      1.00      5.5±0.01µs        ? ?/sec    1.00      5.5±0.00µs        ? ?/sec
sort string[0-100] nulls to indices 2^12                1.00     27.9±0.10µs        ? ?/sec    1.00     27.9±0.09µs        ? ?/sec
sort string[0-100] to indices 2^12                      1.00     53.2±0.21µs        ? ?/sec    1.00     53.1±0.19µs        ? ?/sec
sort string[0-10] nulls to indices 2^12                 1.01     30.0±0.10µs        ? ?/sec    1.00     29.8±0.08µs        ? ?/sec
sort string[0-10] to indices 2^12                       1.00     57.2±0.20µs        ? ?/sec    1.00     57.2±0.19µs        ? ?/sec
sort string[0-400] nulls to indices 2^12                1.00     28.3±0.09µs        ? ?/sec    1.00     28.2±0.10µs        ? ?/sec
sort string[0-400] to indices 2^12                      1.01     53.8±0.22µs        ? ?/sec    1.00     53.5±0.19µs        ? ?/sec
sort string[1000] nulls to indices 2^12                 1.00     29.0±0.10µs        ? ?/sec    1.00     28.9±0.11µs        ? ?/sec
sort string[1000] to indices 2^12                       1.00     53.5±0.17µs        ? ?/sec    1.00     53.5±0.22µs        ? ?/sec
sort string[100] nulls to indices 2^12                  1.00     28.2±0.11µs        ? ?/sec    1.00     28.2±0.09µs        ? ?/sec
sort string[100] to indices 2^12                        1.00     53.4±0.18µs        ? ?/sec    1.00     53.3±0.19µs        ? ?/sec
sort string[10] dict nulls to indices 2^12              1.01    100.2±0.23µs        ? ?/sec    1.00     98.9±0.11µs        ? ?/sec
sort string[10] dict to indices 2^12                    1.01    209.7±0.45µs        ? ?/sec    1.00    206.7±0.50µs        ? ?/sec
sort string[10] nulls to indices 2^12                   1.00     28.8±0.09µs        ? ?/sec    1.00     28.7±0.10µs        ? ?/sec
sort string[10] to indices 2^12                         1.02     53.2±0.21µs        ? ?/sec    1.00     52.2±0.19µs        ? ?/sec
sort string_view[0-400] nulls to indices 2^12           1.00     36.2±0.05µs        ? ?/sec    1.01     36.5±0.02µs        ? ?/sec
sort string_view[0-400] to indices 2^12                 1.10     81.1±0.21µs        ? ?/sec    1.00     73.9±0.26µs        ? ?/sec
sort string_view[10] nulls to indices 2^12              1.00     32.7±0.06µs        ? ?/sec    1.00     32.7±0.02µs        ? ?/sec
sort string_view[10] to indices 2^12                    1.00     62.5±0.10µs        ? ?/sec    1.00     62.4±0.06µs        ? ?/sec
sort string_view_inlined[0-12] nulls to indices 2^12    1.09     35.0±0.09µs        ? ?/sec    1.00     32.1±0.02µs        ? ?/sec
sort string_view_inlined[0-12] to indices 2^12          1.00     67.4±0.16µs        ? ?/sec    1.00     67.4±0.19µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 545.1s
Peak memory 22.7 MiB
Avg memory 13.3 MiB
CPU user 540.3s
CPU sys 0.1s
Peak spill 0 B

branch

Metric Value
Wall time 550.1s
Peak memory 23.3 MiB
Avg memory 15.3 MiB
CPU user 544.6s
CPU sys 0.1s
Peak spill 0 B

File an issue against this benchmark runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-ord performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants