Skip to content

Skip zero-fill of hash buffer by writing null sentinels#21347

Draft
Dandandan wants to merge 1 commit intoapache:mainfrom
Dandandan:skip-zero-fill-hash-buffer
Draft

Skip zero-fill of hash buffer by writing null sentinels#21347
Dandandan wants to merge 1 commit intoapache:mainfrom
Dandandan:skip-zero-fill-hash-buffer

Conversation

@Dandandan
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

N/A - performance optimization

Rationale for this change

Profiling ClickBench queries showed __bzero (from buffer.resize(n, 0)) as ~1-2% of CPU time in with_hashes / create_hashes. The zero-fill is unnecessary when hash functions write all positions including nulls.

What changes are included in this PR?

Hash functions now write all buffer positions when rehash=false (first column), using a consistent null sentinel hash (random_state.hash_one(1u8)) for null positions. This allows with_hashes to skip the zero-fill entirely.

  • with_hashes: use set_len instead of resize(n, 0) — avoids memset
  • hash_array_primitive / hash_array: fill with null sentinel, then overwrite valid positions via valid_indices()
  • hash_string_view_array_inner: write null sentinel instead of continue for null positions
  • hash_dictionary_inner: write null sentinel for null keys/values
  • hash_run_array_inner: fill null run ranges with sentinel
  • create_hashes: zero-fill only for complex types (struct, list, map, union) whose hash functions always combine with existing values

Benchmark results (with_hashes bench, int64 single column):

  • No nulls: 3.3µs → 2.8µs (~17% faster)
  • With nulls: ~9.6µs (unchanged — fill + iterate is same cost as resize + iterate)

Are these changes tested?

Existing tests updated to expect non-zero null sentinel hash values.

Are there any user-facing changes?

No. Null positions now get a consistent non-zero hash instead of 0, but this is an internal implementation detail.

🤖 Generated with Claude Code

Hash functions now write all positions including nulls (using a
consistent null sentinel hash) when rehash=false (first column).
This allows with_hashes to skip the buffer zero-fill, saving ~0.5µs
per 8192-element batch on the no-nulls hot path.

Changes:
- with_hashes: use unsafe set_len instead of resize(n, 0)
- hash_array_primitive/hash_array: fill with null sentinel then
  overwrite valid positions via valid_indices()
- hash_string_view_array_inner: write null sentinel instead of skip
- hash_dictionary_inner: write null sentinel for null keys/values
- hash_run_array_inner: fill null run ranges with sentinel
- create_hashes: zero-fill only for complex types (struct, list, map,
  union) whose hash functions always combine with existing values

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added the common Related to common crate label Apr 3, 2026
@Dandandan
Copy link
Copy Markdown
Contributor Author

run benchmark with_hashes

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4183748133-751-7zzzc 6.12.55+ #1 SMP Sun Feb 1 08:59:41 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 skip-zero-fill-hash-buffer (7056098) to 1e93a67 (merge-base) diff
BENCH_NAME=with_hashes
BENCH_COMMAND=cargo bench --features=parquet --bench with_hashes
BENCH_FILTER=
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark completed (GKE) | trigger

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

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                                   skip-zero-fill-hash-buffer
-----                                        ----                                   --------------------------
dense_union: multiple, no nulls              1.01    239.1±0.30µs        ? ?/sec    1.00    237.8±0.38µs        ? ?/sec
dense_union: single, no nulls                1.00     79.9±0.10µs        ? ?/sec    1.00     79.6±0.17µs        ? ?/sec
dictionary_utf8_int32: multiple, no nulls    1.03     14.6±0.02µs        ? ?/sec    1.00     14.2±0.17µs        ? ?/sec
dictionary_utf8_int32: multiple, nulls       1.03     32.7±0.04µs        ? ?/sec    1.00     31.7±0.02µs        ? ?/sec
dictionary_utf8_int32: single, no nulls      1.07      4.6±0.03µs        ? ?/sec    1.00      4.3±0.07µs        ? ?/sec
dictionary_utf8_int32: single, nulls         1.03     10.9±0.01µs        ? ?/sec    1.00     10.5±0.00µs        ? ?/sec
int64: multiple, no nulls                    1.02     16.9±0.01µs        ? ?/sec    1.00     16.6±0.01µs        ? ?/sec
int64: multiple, nulls                       1.00     26.8±0.01µs        ? ?/sec    1.08     29.0±0.05µs        ? ?/sec
int64: single, no nulls                      1.09      4.6±0.02µs        ? ?/sec    1.00      4.2±0.01µs        ? ?/sec
int64: single, nulls                         1.00      8.8±0.00µs        ? ?/sec    1.04      9.1±0.01µs        ? ?/sec
large_utf8: multiple, no nulls               1.08    112.0±0.44µs        ? ?/sec    1.00    104.1±0.59µs        ? ?/sec
large_utf8: multiple, nulls                  1.00    159.4±0.66µs        ? ?/sec    1.02    162.0±0.89µs        ? ?/sec
large_utf8: single, no nulls                 1.00     26.7±0.19µs        ? ?/sec    1.27     34.0±0.09µs        ? ?/sec
large_utf8: single, nulls                    1.00     44.6±0.70µs        ? ?/sec    1.02     45.6±0.58µs        ? ?/sec
list_array: multiple, no nulls               1.00    145.2±0.17µs        ? ?/sec    1.05    152.6±0.37µs        ? ?/sec
list_array: multiple, nulls                  1.00    175.3±0.33µs        ? ?/sec    1.01    176.8±0.21µs        ? ?/sec
list_array: single, no nulls                 1.00     48.7±0.04µs        ? ?/sec    1.04     50.6±0.78µs        ? ?/sec
list_array: single, nulls                    1.00     58.7±0.11µs        ? ?/sec    1.01     59.5±0.12µs        ? ?/sec
list_array_sliced: 1/10 of 81920 rows        1.00     48.7±0.07µs        ? ?/sec    1.01     49.0±0.04µs        ? ?/sec
list_array_sliced: 1/2 of 16384 rows         1.00     50.9±0.09µs        ? ?/sec    1.00     50.8±0.97µs        ? ?/sec
list_array_sliced: 1/5 of 40960 rows         1.03     50.8±0.13µs        ? ?/sec    1.00     49.2±0.05µs        ? ?/sec
map_array: multiple, no nulls                1.00    241.3±0.17µs        ? ?/sec    1.01    242.8±0.18µs        ? ?/sec
map_array: multiple, nulls                   1.00    246.0±0.34µs        ? ?/sec    1.01    249.0±0.15µs        ? ?/sec
map_array: single, no nulls                  1.00     80.7±0.05µs        ? ?/sec    1.01     81.2±0.06µs        ? ?/sec
map_array: single, nulls                     1.00     82.4±0.12µs        ? ?/sec    1.01     83.3±0.05µs        ? ?/sec
map_array_sliced: 1/10 of 81920 rows         1.00     81.4±0.11µs        ? ?/sec    1.00     81.2±0.22µs        ? ?/sec
map_array_sliced: 1/2 of 16384 rows          1.00     81.0±0.05µs        ? ?/sec    1.00     81.3±0.10µs        ? ?/sec
map_array_sliced: 1/5 of 40960 rows          1.00     81.0±0.05µs        ? ?/sec    1.01     81.5±0.04µs        ? ?/sec
run_array_int32: multiple, no nulls          1.09      5.0±0.01µs        ? ?/sec    1.00      4.6±0.01µs        ? ?/sec
run_array_int32: multiple, nulls             1.02      6.7±0.01µs        ? ?/sec    1.00      6.6±0.01µs        ? ?/sec
run_array_int32: single, no nulls            1.29   1817.2±5.69ns        ? ?/sec    1.00   1406.2±7.28ns        ? ?/sec
run_array_int32: single, nulls               1.09      2.4±0.01µs        ? ?/sec    1.00      2.2±0.00µs        ? ?/sec
sparse_union: multiple, no nulls             1.00    261.3±0.41µs        ? ?/sec    1.00    260.7±0.56µs        ? ?/sec
sparse_union: single, no nulls               1.00     87.4±0.13µs        ? ?/sec    1.00     87.2±0.24µs        ? ?/sec
sparse_union_sliced: 1/10 of 81920 rows      1.01     87.9±0.16µs        ? ?/sec    1.00     87.0±0.40µs        ? ?/sec
sparse_union_sliced: 1/2 of 16384 rows       1.00     87.4±0.11µs        ? ?/sec    1.00     87.0±0.37µs        ? ?/sec
sparse_union_sliced: 1/5 of 40960 rows       1.01     87.6±0.19µs        ? ?/sec    1.00     87.2±0.36µs        ? ?/sec
struct_array: multiple, no nulls             1.15    188.3±2.47µs        ? ?/sec    1.00    163.3±0.22µs        ? ?/sec
struct_array: multiple, nulls                1.13    194.5±1.76µs        ? ?/sec    1.00    172.8±0.22µs        ? ?/sec
struct_array: single, no nulls               1.14     62.2±0.37µs        ? ?/sec    1.00     54.6±0.20µs        ? ?/sec
struct_array: single, nulls                  1.13     65.2±0.10µs        ? ?/sec    1.00     58.0±0.15µs        ? ?/sec
utf8: multiple, no nulls                     1.06    108.0±0.31µs        ? ?/sec    1.00    102.3±0.36µs        ? ?/sec
utf8: multiple, nulls                        1.41   192.6±20.68µs        ? ?/sec    1.00    136.4±0.72µs        ? ?/sec
utf8: single, no nulls                       1.28     33.7±0.59µs        ? ?/sec    1.00     26.4±0.32µs        ? ?/sec
utf8: single, nulls                          1.26     46.7±1.25µs        ? ?/sec    1.00     36.9±0.36µs        ? ?/sec
utf8_view (small): multiple, no nulls        1.02     19.0±0.01µs        ? ?/sec    1.00     18.6±0.00µs        ? ?/sec
utf8_view (small): multiple, nulls           1.01     29.0±0.02µs        ? ?/sec    1.00     28.8±0.02µs        ? ?/sec
utf8_view (small): single, no nulls          1.06      5.1±0.04µs        ? ?/sec    1.00      4.8±0.00µs        ? ?/sec
utf8_view (small): single, nulls             1.02      9.7±0.01µs        ? ?/sec    1.00      9.5±0.01µs        ? ?/sec
utf8_view: multiple, no nulls                1.02    109.0±0.27µs        ? ?/sec    1.00    107.3±0.62µs        ? ?/sec
utf8_view: multiple, nulls                   1.00    113.0±0.25µs        ? ?/sec    1.04    117.6±1.23µs        ? ?/sec
utf8_view: single, no nulls                  1.00     32.9±0.03µs        ? ?/sec    1.13     37.1±0.09µs        ? ?/sec
utf8_view: single, nulls                     1.00     35.7±0.10µs        ? ?/sec    1.07     38.4±0.11µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 526.5s
Peak memory 3.3 GiB
Avg memory 3.3 GiB
CPU user 660.5s
CPU sys 2.9s
Disk read 0 B
Disk write 553.0 MiB

branch

Metric Value
Wall time 528.6s
Peak memory 3.4 GiB
Avg memory 3.3 GiB
CPU user 665.0s
CPU sys 0.7s
Disk read 0 B
Disk write 14.0 MiB

File an issue against this benchmark runner

@Dandandan Dandandan marked this pull request as draft April 3, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants