Skip to content

perf(nullbuf::expand) non aligned counts - #10980

Open
Rich-T-kid wants to merge 4 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/optimize-non-aligned-expand
Open

perf(nullbuf::expand) non aligned counts#10980
Rich-T-kid wants to merge 4 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/optimize-non-aligned-expand

Conversation

@Rich-T-kid

@Rich-T-kid Rich-T-kid commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

note I did use ai to help me with the bit maniluplation logic!

Which issue does this PR close?

Rationale for this change

NullBuffer::expand now has a fast path for count % 8 == 0 (byte-aligned) and count % 4 == 0 (nibble-aligned) counts. For all other values of count the fallback iterated every bit individually, calling set_bit per valid index. This is O(n × count) bit-level writes even when the validity buffer is mostly non-null.

What changes are included in this PR?

Replaces the bit-by-bit fallback in NullBuffer::try_expand with a BitSliceIterator based approach that works over contiguous runs of valid bits rather than individual bits. For each run [start, end) it computes the output byte range [startcount/8, endcount/8] and sets it with byte-level OR masks:

  • A partial leading byte is ORed with 0xFF << start_offset.
  • Full interior bytes are filled with 0xFF.
  • A partial trailing byte is ORed with (1 << end_offset) - 1.
  • When the entire run fits in a single byte, both masks are ANDed together.

Are these changes tested?

yes, test was introduced in #10976

Are there any user-facing changes?

no

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-buffer labels Sep 4, 2026
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

run benchmark take_kernels
env:
BENCH_FILTER: fixed_size_list

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c5535077865-2129-8wrbz 6.12.94+ #1 SMP Fri Jul 17 09:42:57 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 rich-T-kid/optimize-non-aligned-expand (1f37f77) to ec21627 (merge-base) diff

Run configuration
run benchmark take_kernels
env:
  BENCH_FILTER: "fixed_size_list"

BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench take_kernels
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 rich-T-kid/optimize-non-aligned-expand (1f37f77) to ec21627 (merge-base) diff

Run configuration
run benchmark take_kernels
env:
  BENCH_FILTER: "fixed_size_list"
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                                   rich-T-kid_optimize-non-aligned-expand
-----                                              ----                                   --------------------------------------
take fixed_size_list<i32>[22] 1024                 1.01      3.4±0.01µs        ? ?/sec    1.00      3.4±0.00µs        ? ?/sec
take fixed_size_list<i32>[22] null indices 1024    3.34     20.7±0.02µs        ? ?/sec    1.00      6.2±0.01µs        ? ?/sec
take fixed_size_list<i32>[22] null values 1024     2.86     21.7±0.02µs        ? ?/sec    1.00      7.6±0.01µs        ? ?/sec
take fixed_size_list<i32>[8] 1024                  1.01      2.8±0.00µs        ? ?/sec    1.00      2.8±0.00µs        ? ?/sec
take fixed_size_list<i32>[8] null indices 1024     2.27      9.4±0.01µs        ? ?/sec    1.00      4.2±0.01µs        ? ?/sec
take fixed_size_list<i32>[8] null values 1024      1.92     10.5±0.01µs        ? ?/sec    1.00      5.5±0.00µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 65.0s
Peak memory 15.8 MiB
Avg memory 13.8 MiB
CPU user 61.8s
CPU sys 0.0s
Peak spill 0 B

branch

Metric Value
Wall time 60.0s
Peak memory 16.0 MiB
Avg memory 13.6 MiB
CPU user 57.1s
CPU sys 0.0s
Peak spill 0 B

File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

nice

take fixed_size_list<i32>[22] null indices 1024    3.34     20.7±0.02µs        ? ?/sec    1.00      6.2±0.01µs        ? ?/sec
take fixed_size_list<i32>[22] null values 1024     2.86     21.7±0.02µs        ? ?/sec    1.00      7.6±0.01µs        ? ?/sec

…counts

Use BitSliceIterator to process runs of valid bits at a time rather
than calling set_bit once per bit per count. For a run [start, end
of valid source bits the output range [start*count, end*count) is
filled by OR-masking the two boundary bytes and memsetting interior
bytes to 0xFF.

Benchmarks (len=1024, alternating 4 valid / 4 null):
  count=7:  2.54 µs → 442 ns  (-83%)
  count=17: 8.15 µs → 441 ns  (-95%)
  count=29: 16.9 µs → 580 ns  (-97%)
EOF
)
@Rich-T-kid
Rich-T-kid force-pushed the rich-T-kid/optimize-non-aligned-expand branch from 1f37f77 to 95fadd0 Compare September 4, 2026 12:39
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

run benchmark take_kernels
env:
BENCH_FILTER: fixed_size_list

1 similar comment
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

run benchmark take_kernels
env:
BENCH_FILTER: fixed_size_list

@Rich-T-kid
Rich-T-kid marked this pull request as ready for review September 4, 2026 12:44
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

@Jefffrey this is also ready for review now. split it from the other PR since it has a lot of bit manipulation logic.

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c5540605236-2131-6g7j5 6.12.94+ #1 SMP Fri Jul 17 09:42:57 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 rich-T-kid/optimize-non-aligned-expand (623846c) to cb682a2 (merge-base) diff

Run configuration
run benchmark take_kernels
env:
  BENCH_FILTER: "fixed_size_list"

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


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c5540605984-2132-d48w9 6.12.94+ #1 SMP Fri Jul 17 09:42:57 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 rich-T-kid/optimize-non-aligned-expand (623846c) to cb682a2 (merge-base) diff

Run configuration
run benchmark take_kernels
env:
  BENCH_FILTER: "fixed_size_list"

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


File an issue against this benchmark runner

@Rich-T-kid Rich-T-kid changed the title draft perf(nullbuf::expand) non aligned counts perf(nullbuf::expand) non aligned counts Sep 4, 2026
@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

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

Comparing rich-T-kid/optimize-non-aligned-expand (623846c) to cb682a2 (merge-base) diff

Run configuration
run benchmark take_kernels
env:
  BENCH_FILTER: "fixed_size_list"
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                                   rich-T-kid_optimize-non-aligned-expand
-----                                              ----                                   --------------------------------------
take fixed_size_list<i32>[22] 1024                 1.01      3.5±0.01µs        ? ?/sec    1.00      3.5±0.01µs        ? ?/sec
take fixed_size_list<i32>[22] null indices 1024    3.22     19.7±0.01µs        ? ?/sec    1.00      6.1±0.01µs        ? ?/sec
take fixed_size_list<i32>[22] null values 1024     2.75     20.7±0.03µs        ? ?/sec    1.00      7.5±0.01µs        ? ?/sec
take fixed_size_list<i32>[8] 1024                  1.00      2.8±0.01µs        ? ?/sec    1.00      2.8±0.01µs        ? ?/sec
take fixed_size_list<i32>[8] null indices 1024     1.00      4.2±0.01µs        ? ?/sec    1.00      4.2±0.01µs        ? ?/sec
take fixed_size_list<i32>[8] null values 1024      1.01      5.6±0.01µs        ? ?/sec    1.00      5.5±0.01µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 65.0s
Peak memory 16.5 MiB
Avg memory 14.2 MiB
CPU user 61.8s
CPU sys 0.0s
Peak spill 0 B

branch

Metric Value
Wall time 60.0s
Peak memory 16.2 MiB
Avg memory 14.1 MiB
CPU user 57.1s
CPU sys 0.0s
Peak spill 0 B

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 rich-T-kid/optimize-non-aligned-expand (623846c) to cb682a2 (merge-base) diff

Run configuration
run benchmark take_kernels
env:
  BENCH_FILTER: "fixed_size_list"
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                                   rich-T-kid_optimize-non-aligned-expand
-----                                              ----                                   --------------------------------------
take fixed_size_list<i32>[22] 1024                 1.01      3.5±0.01µs        ? ?/sec    1.00      3.4±0.01µs        ? ?/sec
take fixed_size_list<i32>[22] null indices 1024    3.25     19.8±0.02µs        ? ?/sec    1.00      6.1±0.01µs        ? ?/sec
take fixed_size_list<i32>[22] null values 1024     2.75     20.7±0.01µs        ? ?/sec    1.00      7.5±0.02µs        ? ?/sec
take fixed_size_list<i32>[8] 1024                  1.00      2.8±0.00µs        ? ?/sec    1.02      2.8±0.00µs        ? ?/sec
take fixed_size_list<i32>[8] null indices 1024     1.02      4.2±0.01µs        ? ?/sec    1.00      4.1±0.01µs        ? ?/sec
take fixed_size_list<i32>[8] null values 1024      1.00      5.5±0.01µs        ? ?/sec    1.00      5.5±0.01µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 65.0s
Peak memory 16.5 MiB
Avg memory 14.2 MiB
CPU user 61.8s
CPU sys 0.0s
Peak spill 0 B

branch

Metric Value
Wall time 60.0s
Peak memory 15.8 MiB
Avg memory 13.8 MiB
CPU user 57.1s
CPU sys 0.0s
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-buffer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants