Skip to content

perf(parquet): compute dictionary array statistics from the values the rows reference - #12401

Open
shanielh wants to merge 4 commits into
apache:mainfrom
shanielh:revive-dict-array-statistics
Open

shanielh wants to merge 4 commits into
apache:mainfrom
shanielh:revive-dict-array-statistics

Conversation

@shanielh

@shanielh shanielh commented Nov 22, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

None. This revives #12282 by @dtenedor, which was closed without being merged and without a stated reason. Its commit is kept as authored; one commit on top fixes a small regression it introduced on the per-row path.

Rationale for this change

When the ArrowWriter writes an Arrow dictionary array of strings or binary, it updates the page statistics by comparing every row's value with the running min and max: two memcmp calls per row. With the dictionary cache from #11982, interning is already one lookup per row, so these comparisons are now most of the cost of writing a low-cardinality dictionary column.

A batch of rows can only reference values from the dictionary, so its min and max are the min and max of the values it references, however many rows reference each one.

What changes are included in this PR?

While a page's rows reference the same arrow dictionary (the same Arc), the encoder remembers in a bitmap which of its values were already folded into the page's statistics, and folds only the values the rows reference for the first time. Once every value is folded, later mini-batches skip the statistics entirely. The bitmap is reset when the page is flushed or the dictionary changes.

Folding only a value's first row in the page gives the same statistics as folding every row, because the comparisons are strict and a repeat of a value already folded never replaces it. So the newly referenced values go through the same compute_min_max (and is_greater) and geospatial accumulator as the per-row path, and geospatial and decimal columns take this path too. It runs whenever the writer uses its dictionary cache from #11982; the statistics, and so the file, are unchanged.

Commits:

  • The original commit from perf(parquet): compute dictionary array statistics from the values the rows reference #12282, unchanged: marks the keys a mini-batch's rows use, then compares each referenced dictionary value once. See perf(parquet): compute dictionary array statistics from the values the rows reference #12282 for its description.
  • #[inline(always)] on update_min_max: moving the per-row min/max update into it made the per-row path +0.50% ± 0.13% instructions on string_dictionary_1pct_cardinality; this restores main's count (−0.02%).
  • Review: the test uses a seeded StdRng and no 100,000-value dictionary.
  • Review: the per-page bitmap kept on the encoder and keyed by the dictionary's Arc, replacing the per-mini-batch Vec<bool>, as described above. A key outside the dictionary now panics when its value is read, instead of falling back to the per-row path. update_statistics is #[inline(never)]: with encode its only caller per array type, LLVM inlined it and the per-row loop took more instructions than on main. Out of line, every update_statistics and encode compiles to the same machine code as main (checked by disassembling both builds).

Are these changes tested?

  • test_dictionary_array_writes_same_file_as_its_values (from perf(parquet): compute dictionary array statistics from the values the rows reference #12282): dictionary arrays of 1 to 2,000 values with null keys and null values, written as the same dictionary twice and then a different one, produce the same file as their values cast to Utf8. Removing the reset when the page is flushed, or when the dictionary changes, fails it.
  • test_write_statistics_arrow_dictionary (new, geospatial feature): a dictionary of WKB points writes the same file, including its geospatial statistics, as its values cast to Binary.
  • The parquet tests pass with --all-features, apart from the three invalid_utf8 reader tests, which fail the same way on main.

Before / after

Measured before review, at c58117b; the retired-instruction tables below are for the current head. arrow_writer bench (string_dictionary* cases), GCP c4a-standard-16 spot VM (Google Axion, aarch64, 16 vCPU), Debian 12, rust stable, otherwise idle; median of two alternating rounds per tree (main, PR, main, PR):

arrow_writer bench, default main PR Speedup
string_dictionary_low_cardinality_20 11.524 ms 4.102 ms 2.81x
string_dictionary_low_cardinality_100 11.589 ms 4.613 ms 2.51x
string_dictionary_low_cardinality_400 11.680 ms 6.177 ms 1.89x
string_dictionary_1pct_cardinality (per-row path) 13.057 ms 12.898 ms 1.01x
string_dictionary (per-row path) 42.605 ms 42.606 ms 1.00x

The other property sets follow the same pattern: low-cardinality dictionaries are 1.83x to 2.81x faster with bloom_filter, parquet_2, zstd and zstd_parquet_2, 1.69x to 2.18x with cdc, and 1.19x to 1.27x with number_distinct_values; the per-row cases are 1.00x to 1.01x.

All 35 cases
arrow_writer bench main PR Speedup
string_dictionary_low_cardinality_20/default 11.524 ms 4.102 ms 2.81x
string_dictionary_low_cardinality_20/bloom_filter 11.669 ms 4.209 ms 2.77x
string_dictionary_low_cardinality_20/parquet_2 11.537 ms 4.113 ms 2.81x
string_dictionary_low_cardinality_20/zstd 11.705 ms 4.260 ms 2.75x
string_dictionary_low_cardinality_20/zstd_parquet_2 11.657 ms 4.231 ms 2.76x
string_dictionary_low_cardinality_20/cdc 14.066 ms 6.459 ms 2.18x
string_dictionary_low_cardinality_20/number_distinct_values 34.700 ms 27.334 ms 1.27x
string_dictionary_low_cardinality_100/default 11.589 ms 4.613 ms 2.51x
string_dictionary_low_cardinality_100/bloom_filter 11.732 ms 4.743 ms 2.47x
string_dictionary_low_cardinality_100/parquet_2 11.593 ms 4.616 ms 2.51x
string_dictionary_low_cardinality_100/zstd 11.956 ms 4.966 ms 2.41x
string_dictionary_low_cardinality_100/zstd_parquet_2 11.931 ms 4.940 ms 2.42x
string_dictionary_low_cardinality_100/cdc 14.084 ms 6.895 ms 2.04x
string_dictionary_low_cardinality_100/number_distinct_values 34.660 ms 27.734 ms 1.25x
string_dictionary_low_cardinality_400/default 11.680 ms 6.177 ms 1.89x
string_dictionary_low_cardinality_400/bloom_filter 11.831 ms 6.291 ms 1.88x
string_dictionary_low_cardinality_400/parquet_2 11.694 ms 6.184 ms 1.89x
string_dictionary_low_cardinality_400/zstd 12.188 ms 6.669 ms 1.83x
string_dictionary_low_cardinality_400/zstd_parquet_2 12.139 ms 6.637 ms 1.83x
string_dictionary_low_cardinality_400/cdc 14.177 ms 8.403 ms 1.69x
string_dictionary_low_cardinality_400/number_distinct_values 34.915 ms 29.432 ms 1.19x
string_dictionary_1pct_cardinality/default 13.057 ms 12.898 ms 1.01x
string_dictionary_1pct_cardinality/bloom_filter 13.504 ms 13.431 ms 1.01x
string_dictionary_1pct_cardinality/parquet_2 12.931 ms 12.872 ms 1.00x
string_dictionary_1pct_cardinality/zstd 15.748 ms 15.676 ms 1.00x
string_dictionary_1pct_cardinality/zstd_parquet_2 15.634 ms 15.619 ms 1.00x
string_dictionary_1pct_cardinality/cdc 16.108 ms 16.418 ms 0.98x
string_dictionary_1pct_cardinality/number_distinct_values 31.861 ms 31.804 ms 1.00x
string_dictionary/default 42.605 ms 42.606 ms 1.00x
string_dictionary/bloom_filter 93.483 ms 93.292 ms 1.00x
string_dictionary/parquet_2 48.608 ms 48.474 ms 1.00x
string_dictionary/zstd 215.190 ms 215.414 ms 1.00x
string_dictionary/zstd_parquet_2 193.010 ms 192.491 ms 1.00x
string_dictionary/cdc 47.762 ms 47.586 ms 1.00x
string_dictionary/number_distinct_values 100.015 ms 99.778 ms 1.00x

string_dictionary_1pct_cardinality/cdc read 0.98x in these two rounds, one of the PR's being slow (16.625 ms against 16.211 ms). Five more alternating rounds of that case alone gave 16.19 ms (main) and 16.22 ms (PR), within main's own spread of 16.00 to 16.50 ms.

Retired instructions

Wall-clock benchmarks on a loaded development machine were too noisy to read, so the change is also measured by retired instructions and cycles on Apple M5 Pro (aarch64, macOS): a small fixed-work program builds the same batches as the benches (same generators, seed and 1M-row size), plus random-key and large-dictionary variants, and writes each one 10 times to an empty sink with the bench's writer properties. The cost per write is the count of 10 writes minus that of 0. Median of five alternating rounds; instruction counts repeat within about ±0.5% (±1% for the two largest dictionaries, whose interner hashing varies run to run), cycles within about ±5% except for the two largest dictionaries, which drift by up to 40% from round to round in both trees.

Batch, default Instructions, main PR Change Cycles, main PR Change Statistics' cost, main PR
string_dictionary_low_cardinality_20 145.7 M 46.5 M -68.1% 33.3 M 7.5 M -77.3% 100.6 M 1.4 M
string_dictionary_low_cardinality_100 141.3 M 46.8 M -66.9% 31.5 M 7.7 M -75.5% 96.2 M 1.7 M
string_dictionary_low_cardinality_400 138.8 M 48.3 M -65.2% 40.1 M 8.4 M -78.9% 93.8 M 3.2 M
400 values, random keys 139.6 M 50.5 M -63.8% 43.6 M 9.2 M -78.8% 94.6 M 5.4 M
1024 values, random keys 142.7 M 59.4 M -58.4% 44.3 M 11.4 M -74.2% 96.2 M 12.9 M
1024 values, one key per mini-batch 156.7 M 61.4 M -60.8% 21.3 M 8.9 M -58.4% 113.7 M 18.4 M
string_dictionary_1pct_cardinality 163.3 M 154.3 M -5.5% 28.6 M 26.4 M -7.9% 85.2 M 76.2 M
string_dictionary (every value unique) 328.1 M 328.0 M -0.0% 118.9 M 117.1 M -1.4% 86.0 M 86.8 M
1M values, random keys 201.6 M 202.4 M +0.4% 245.5 M 266.1 M (noise) 96.8 M 98.1 M
2M values, random keys (no dictionary cache) 201.1 M 200.8 M -0.2% 376.3 M 360.3 M (noise) 97.0 M 96.1 M
Plain Utf8, 100 values (no dictionary array) 288.6 M 284.6 M -1.4% 49.7 M 49.9 M +0.5% 97.5 M 95.6 M

The statistics' cost is the extra instructions with statistics on (default) relative to EnabledStatistics::None on the same tree.

Where the gain comes from

The gain is the per-row statistics comparisons the dictionary path no longer makes: each value is compared once per page, and a mini-batch whose dictionary values are all folded does no statistics work. Before review the PR compared each referenced value once per mini-batch, which left 13 M to 74 M instructions of statistics' cost on the low-cardinality and 1024-value cases above; keeping the folded values across mini-batches takes that to 1 M to 18 M.

What remains is the bit test per row while a page still has values left to fold (the 1024-value cases, where each mini-batch references new values), and per-row work on dictionaries where most rows reference a value for the first time (string_dictionary, 1M values).

Slower inputs: none measured beyond noise. The 1M-value dictionary is 17 MB, so it overflows the 1 MiB dictionary page and falls back to plain encoding after 51,200 rows; the other 95% of its rows take main's per-row path, whose machine code is unchanged. The rows before the fallback reference a value for the first time almost every time, so the bitmap only adds a bit test and a push per row there: +0.4% instructions, within that case's ±1%.

A production workload

Measured before review, at c58117b: on a Parquet sort-compaction workload (about 230 columns, most of them low-cardinality strings written from dictionary arrays), the change applied to parquet 60.2.0 reduced the compaction's total retired instructions by 6.2% (862 G to 809 G, three runs each) and its CPU time by 5.8%, with identical output.

Are there any significant user-facing changes?

No.

AI usage disclosure

The original commit was written as described in #12282. For this revival, an AI coding agent (Claude Code) rebased it, found and fixed the per-row regression, wrote the measurement program (including the random-key and boundary cases), ran the measurements and drafted this description, which the submitter reviewed. In review it made the changes listed above, choosing with the submitter how to address each comment.

🤖 Generated with Claude Code

dtenedor and others added 2 commits November 23, 2026 10:37
…e rows reference

Writing an Arrow dictionary array compared every row's value against the
page's min and max. When the dictionary is no larger than the batch, mark the
keys the rows use and compare each referenced value once instead. Decimals,
geospatial statistics and larger dictionaries keep the per-row computation.

Co-authored-by: Isaac <[email protected]>
Moving the per-row statistics' min/max update into `update_min_max` cost the
per-row path +0.50% ± 0.13% instructions on `string_dictionary_1pct_cardinality`
(macOS aarch64, retired instructions over 10 alternating rounds), where the
dictionary is larger than a mini-batch and the change otherwise does nothing.
Forcing it inline restores main's count (−0.02%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jefffrey

Copy link
Copy Markdown
Contributor

run benchmark arrow_writer
env:
BENCH_FILTER: string_dictionary

@adriangbot

This comment was marked as duplicate.

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: arrow_writer

Comparing revive-dict-array-statistics (c58117b) to 6747ecd (merge-base) diff

Run configuration
run benchmark arrow_writer
env:
  BENCH_FILTER: string_dictionary
shards: 1
Details
group                                                           base                                   changed
-----                                                           ----                                   -------
string_dictionary/bloom_filter                                  1.00     85.6±7.82ms 11.7 MElem/sec    1.06    90.4±14.71ms 11.1 MElem/sec
string_dictionary/cdc                                           1.01     49.8±4.94ms 20.1 MElem/sec    1.00     49.4±6.84ms 20.3 MElem/sec
string_dictionary/default                                       1.03     42.7±4.26ms 23.4 MElem/sec    1.00     41.6±4.20ms 24.0 MElem/sec
string_dictionary/number_distinct_values                        1.02   107.7±17.32ms  9.3 MElem/sec    1.00   105.5±14.73ms  9.5 MElem/sec
string_dictionary/parquet_2                                     1.02     51.3±5.91ms 19.5 MElem/sec    1.00     50.2±7.33ms 19.9 MElem/sec
string_dictionary/zstd                                          1.00   223.1±16.04ms  4.5 MElem/sec    1.01   224.7±17.20ms  4.5 MElem/sec
string_dictionary/zstd_parquet_2                                1.00    198.2±9.75ms  5.0 MElem/sec    1.00   198.5±10.46ms  5.0 MElem/sec
string_dictionary_1pct_cardinality/bloom_filter                 1.00     12.3±0.39ms 81.4 MElem/sec    1.03     12.6±0.36ms 79.1 MElem/sec
string_dictionary_1pct_cardinality/cdc                          1.00     15.1±0.36ms 66.0 MElem/sec    1.00     15.2±0.25ms 66.0 MElem/sec
string_dictionary_1pct_cardinality/default                      1.00     11.8±0.16ms 85.0 MElem/sec    1.04     12.2±0.24ms 81.7 MElem/sec
string_dictionary_1pct_cardinality/number_distinct_values       1.00     31.0±0.85ms 32.3 MElem/sec    1.01     31.1±0.92ms 32.1 MElem/sec
string_dictionary_1pct_cardinality/parquet_2                    1.00     11.9±0.25ms 84.1 MElem/sec    1.01     12.0±0.17ms 83.2 MElem/sec
string_dictionary_1pct_cardinality/zstd                         1.00     14.5±0.22ms 68.8 MElem/sec    1.03     14.9±0.33ms 66.9 MElem/sec
string_dictionary_1pct_cardinality/zstd_parquet_2               1.00     14.5±0.33ms 68.8 MElem/sec    1.01     14.7±0.32ms 67.9 MElem/sec
string_dictionary_low_cardinality_100/bloom_filter              2.13     10.4±0.03ms 96.2 MElem/sec    1.00      4.9±0.14ms 205.0 MElem/sec
string_dictionary_low_cardinality_100/cdc                       1.88     12.8±0.16ms 78.1 MElem/sec    1.00      6.8±0.19ms 147.2 MElem/sec
string_dictionary_low_cardinality_100/default                   2.29     10.4±0.07ms 96.3 MElem/sec    1.00      4.5±0.11ms 220.6 MElem/sec
string_dictionary_low_cardinality_100/number_distinct_values    1.21     33.8±0.81ms 29.6 MElem/sec    1.00     27.9±0.85ms 35.9 MElem/sec
string_dictionary_low_cardinality_100/parquet_2                 2.28     10.4±0.06ms 96.5 MElem/sec    1.00      4.5±0.15ms 220.4 MElem/sec
string_dictionary_low_cardinality_100/zstd                      2.25     10.8±0.02ms 92.5 MElem/sec    1.00      4.8±0.02ms 207.9 MElem/sec
string_dictionary_low_cardinality_100/zstd_parquet_2            2.13     10.6±0.03ms 94.0 MElem/sec    1.00      5.0±0.13ms 200.2 MElem/sec
string_dictionary_low_cardinality_20/bloom_filter               2.45     10.4±0.08ms 95.9 MElem/sec    1.00      4.3±0.09ms 234.7 MElem/sec
string_dictionary_low_cardinality_20/cdc                        1.91     12.7±0.11ms 78.5 MElem/sec    1.00      6.7±0.09ms 149.7 MElem/sec
string_dictionary_low_cardinality_20/default                    2.42     10.4±0.11ms 96.4 MElem/sec    1.00      4.3±0.14ms 233.6 MElem/sec
string_dictionary_low_cardinality_20/number_distinct_values     1.23     34.0±0.97ms 29.4 MElem/sec    1.00     27.6±0.84ms 36.2 MElem/sec
string_dictionary_low_cardinality_20/parquet_2                  2.39     10.4±0.04ms 96.6 MElem/sec    1.00      4.3±0.09ms 231.2 MElem/sec
string_dictionary_low_cardinality_20/zstd                       2.36     10.6±0.05ms 94.7 MElem/sec    1.00      4.5±0.11ms 223.7 MElem/sec
string_dictionary_low_cardinality_20/zstd_parquet_2             2.48     10.5±0.09ms 95.2 MElem/sec    1.00      4.2±0.02ms 236.3 MElem/sec
string_dictionary_low_cardinality_400/bloom_filter              1.71     10.5±0.06ms 95.3 MElem/sec    1.00      6.1±0.04ms 163.3 MElem/sec
string_dictionary_low_cardinality_400/cdc                       1.46     12.7±0.03ms 78.5 MElem/sec    1.00      8.7±0.29ms 114.9 MElem/sec
string_dictionary_low_cardinality_400/default                   1.66     10.5±0.11ms 95.6 MElem/sec    1.00      6.3±0.28ms 158.3 MElem/sec
string_dictionary_low_cardinality_400/number_distinct_values    1.15     34.0±1.02ms 29.4 MElem/sec    1.00     29.6±0.91ms 33.7 MElem/sec
string_dictionary_low_cardinality_400/parquet_2                 1.70     10.5±0.10ms 95.3 MElem/sec    1.00      6.2±0.20ms 162.2 MElem/sec
string_dictionary_low_cardinality_400/zstd                      1.67     11.0±0.13ms 91.0 MElem/sec    1.00      6.6±0.16ms 152.2 MElem/sec
string_dictionary_low_cardinality_400/zstd_parquet_2            1.64     10.9±0.12ms 91.6 MElem/sec    1.00      6.7±0.23ms 149.8 MElem/sec

Per-runner information
arrow_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-iv9lhwbu-d3ef1614-wm5p

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

uname:

Linux bench-c7102669552-5629-zd7rd 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writer
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
Resource Usage

base (merge-base)

Metric Value
Wall time 405.1s
Peak memory 1.5 GiB
Avg memory 132.5 MiB
CPU user 397.0s
CPU sys 5.0s
Peak spill 0 B

branch

Metric Value
Wall time 385.1s
Peak memory 2.1 GiB
Avg memory 138.3 MiB
CPU user 377.3s
CPU sys 5.1s
Peak spill 0 B

File an issue against this benchmark runner

@shanielh

Copy link
Copy Markdown
Author

@Jefffrey, you might find #12416 interesting too. It includes related performance enhancements for calculating NDV on dictionary-encoded columns.

@alamb

This comment was marked as outdated.

@adriangbot

This comment was marked as outdated.

@alamb

alamb commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

run benchmark arrow_writer
env:
BENCH_FILTER: string_dictionary

@adriangbot

This comment was marked as duplicate.

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: arrow_writer

Comparing revive-dict-array-statistics (c58117b) to 6747ecd (merge-base) diff

Run configuration
run benchmark arrow_writer
env:
  BENCH_FILTER: string_dictionary
shards: 1
Details
group                                                           base                                   changed
-----                                                           ----                                   -------
string_dictionary/bloom_filter                                  1.03    92.8±10.72ms 10.8 MElem/sec    1.00    90.4±13.96ms 11.1 MElem/sec
string_dictionary/cdc                                           1.02     49.3±7.74ms 20.3 MElem/sec    1.00     48.5±8.44ms 20.6 MElem/sec
string_dictionary/default                                       1.04     43.8±4.86ms 22.8 MElem/sec    1.00     42.1±4.10ms 23.7 MElem/sec
string_dictionary/number_distinct_values                        1.01   104.6±14.58ms  9.6 MElem/sec    1.00   103.3±14.44ms  9.7 MElem/sec
string_dictionary/parquet_2                                     1.03     50.0±6.09ms 20.0 MElem/sec    1.00     48.4±4.91ms 20.7 MElem/sec
string_dictionary/zstd                                          1.01   222.8±16.79ms  4.5 MElem/sec    1.00   220.0±13.89ms  4.5 MElem/sec
string_dictionary/zstd_parquet_2                                1.01    199.3±9.86ms  5.0 MElem/sec    1.00   197.9±11.31ms  5.1 MElem/sec
string_dictionary_1pct_cardinality/bloom_filter                 1.00     12.3±0.38ms 81.6 MElem/sec    1.00     12.3±0.37ms 81.5 MElem/sec
string_dictionary_1pct_cardinality/cdc                          1.01     15.2±0.30ms 65.7 MElem/sec    1.00     15.1±0.29ms 66.2 MElem/sec
string_dictionary_1pct_cardinality/default                      1.00     11.9±0.27ms 84.0 MElem/sec    1.01     12.0±0.22ms 83.5 MElem/sec
string_dictionary_1pct_cardinality/number_distinct_values       1.00     30.8±0.74ms 32.5 MElem/sec    1.01     31.1±0.99ms 32.1 MElem/sec
string_dictionary_1pct_cardinality/parquet_2                    1.01     12.0±0.23ms 83.5 MElem/sec    1.00     11.9±0.24ms 83.9 MElem/sec
string_dictionary_1pct_cardinality/zstd                         1.02     15.0±0.30ms 66.7 MElem/sec    1.00     14.7±0.29ms 68.0 MElem/sec
string_dictionary_1pct_cardinality/zstd_parquet_2               1.00     14.5±0.29ms 69.1 MElem/sec    1.03     14.9±0.17ms 67.1 MElem/sec
string_dictionary_low_cardinality_100/bloom_filter              2.22     10.4±0.11ms 95.9 MElem/sec    1.00      4.7±0.15ms 213.0 MElem/sec
string_dictionary_low_cardinality_100/cdc                       1.81     12.7±0.12ms 78.7 MElem/sec    1.00      7.0±0.50ms 142.3 MElem/sec
string_dictionary_low_cardinality_100/default                   2.30     10.3±0.06ms 96.6 MElem/sec    1.00      4.5±0.12ms 222.2 MElem/sec
string_dictionary_low_cardinality_100/number_distinct_values    1.21     33.7±0.95ms 29.7 MElem/sec    1.00     27.8±0.81ms 35.9 MElem/sec
string_dictionary_low_cardinality_100/parquet_2                 2.28     10.3±0.08ms 96.9 MElem/sec    1.00      4.5±0.15ms 220.5 MElem/sec
string_dictionary_low_cardinality_100/zstd                      2.19     10.7±0.06ms 93.6 MElem/sec    1.00      4.9±0.14ms 205.1 MElem/sec
string_dictionary_low_cardinality_100/zstd_parquet_2            2.22     10.7±0.06ms 93.6 MElem/sec    1.00      4.8±0.11ms 207.7 MElem/sec
string_dictionary_low_cardinality_20/bloom_filter               2.43     10.5±0.04ms 95.3 MElem/sec    1.00      4.3±0.11ms 231.8 MElem/sec
string_dictionary_low_cardinality_20/cdc                        1.99     12.7±0.10ms 78.6 MElem/sec    1.00      6.4±0.13ms 156.1 MElem/sec
string_dictionary_low_cardinality_20/default                    2.45     10.3±0.10ms 96.7 MElem/sec    1.00      4.2±0.11ms 237.2 MElem/sec
string_dictionary_low_cardinality_20/number_distinct_values     1.23     33.9±0.95ms 29.5 MElem/sec    1.00     27.7±0.92ms 36.1 MElem/sec
string_dictionary_low_cardinality_20/parquet_2                  2.47     10.3±0.05ms 96.8 MElem/sec    1.00      4.2±0.09ms 239.2 MElem/sec
string_dictionary_low_cardinality_20/zstd                       2.44     10.5±0.06ms 95.4 MElem/sec    1.00      4.3±0.10ms 233.1 MElem/sec
string_dictionary_low_cardinality_20/zstd_parquet_2             2.42     10.5±0.07ms 95.7 MElem/sec    1.00      4.3±0.11ms 231.1 MElem/sec
string_dictionary_low_cardinality_400/bloom_filter              1.68     10.6±0.11ms 94.5 MElem/sec    1.00      6.3±0.23ms 158.6 MElem/sec
string_dictionary_low_cardinality_400/cdc                       1.42     12.8±0.11ms 78.0 MElem/sec    1.00      9.0±0.61ms 110.8 MElem/sec
string_dictionary_low_cardinality_400/default                   1.65     10.4±0.06ms 95.9 MElem/sec    1.00      6.3±0.20ms 158.2 MElem/sec
string_dictionary_low_cardinality_400/number_distinct_values    1.13     33.7±0.94ms 29.7 MElem/sec    1.00     29.8±0.72ms 33.6 MElem/sec
string_dictionary_low_cardinality_400/parquet_2                 1.71     10.4±0.07ms 95.9 MElem/sec    1.00      6.1±0.19ms 163.9 MElem/sec
string_dictionary_low_cardinality_400/zstd                      1.64     11.0±0.12ms 90.9 MElem/sec    1.00      6.7±0.24ms 149.2 MElem/sec
string_dictionary_low_cardinality_400/zstd_parquet_2            1.67     11.0±0.09ms 91.1 MElem/sec    1.00      6.6±0.19ms 152.4 MElem/sec

Per-runner information
arrow_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-1xvn17if-a66c6c5a-8rvb

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

uname:

Linux bench-c7111631150-5659-gss6r 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writer
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
Resource Usage

base (merge-base)

Metric Value
Wall time 410.1s
Peak memory 1.5 GiB
Avg memory 161.3 MiB
CPU user 398.9s
CPU sys 5.2s
Peak spill 0 B

branch

Metric Value
Wall time 395.1s
Peak memory 2.1 GiB
Avg memory 176.2 MiB
CPU user 384.0s
CPU sys 5.5s
Peak spill 0 B

File an issue against this benchmark runner

@Jefffrey Jefffrey added the performance Speed or memory optimizations label Nov 24, 2026
Comment thread parquet/src/arrow/arrow_writer/mod.rs Resolved
Comment thread parquet/src/arrow/arrow_writer/mod.rs Resolved
@shanielh

Copy link
Copy Markdown
Author

@Jefffrey Thanks for the review, I've addressed your comments.

@shanielh

Copy link
Copy Markdown
Author

@Jefffrey thanks for the approval, anything else needed from me to get this merged? and can you take a look at #12416 too? 🙏

@Jefffrey

Copy link
Copy Markdown
Contributor

ill keep it open for a bit in case others might wanna take a look, cc @Rich-T-kid & @etseidl

@etseidl etseidl 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.

Looks like an improvement to me, thanks!

@alamb alamb 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.

Thanks -- this is a neat idea

I do worry if it will slow down the common case where all values in the dictionary are used

I have some comments. A cheaper potentially faster thing to do could be considering if we could special case seeing the same dictionary

aka if the next batch was the same Arc<...> values we could simply skip updating min/max values as it has already been processed

However, if we are only updating min/max values that are referenced then that might be more complicated.

// compare numerically, so values with different bytes can tie, and which one becomes
// the statistic depends on the order of the rows
if encoder.statistics_enabled == EnabledStatistics::None
|| encoder.geo_stats_accumulator.is_some()

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.

why not also with geo stats?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

✅

}

let keys = values.keys().values();
let mut referenced = vec![false; dictionary_values.len()];

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.

I think the bitmaps (aka BooleanBuffer_ in this crate are far more efficient than Vec<bool> for this sort of thing -- did you consider using them?

We could also avoid this new allocation by saving a BooleanBuffer on the byte array encoder perhaps

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

✅

if let Some(first) = referenced_values.next() {
let (min, max) = referenced_values.fold((first, first), |(min, max), value| {
(
if min.as_ref() > value.as_ref() {

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.

the old code uses is_greater -- is there a reason to do something different here?

@shanielh shanielh Nov 25, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed. The dictionary path now passes the values its rows reference for the first time to the same compute_min_max as the per-row path, so both use is_greater (144e02d).

for &idx in indices {
match referenced.get_mut(keys[idx].as_usize()) {
Some(referenced) => *referenced = true,
// A key outside the dictionary reads as an empty value

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.

this is an error -- in a valid arrow array there should never be an key that is outside the dictionary

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. The fallback is gone. A key outside the dictionary now panics when its value is read, like any out-of-bounds index.

@alamb

alamb commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Or maybe we could have a fast path for when the dictionary is small (64 values? 128 values?)

…er page

While a page's rows reference the same arrow dictionary, remember which of its
values were already folded into the page's statistics, and fold only the
values the rows reference for the first time. Once every value is folded,
later batches skip the statistics entirely.

The newly referenced values go through the same `compute_min_max` and
geospatial accumulator as the per-row path, so geospatial and decimal columns
take this path too, and a key outside the dictionary panics as it does when
indexing the dictionary.

`update_statistics` is marked `#[inline(never)]`: with `encode` its only
caller per array type, LLVM inlined it and the per-row loop took more
instructions than main's, where it is a function of its own. Out of line,
`update_statistics` and `encode` compile to the same machine code as main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@shanielh
shanielh force-pushed the revive-dict-array-statistics branch from f6049c4 to 144e02d Compare November 25, 2026 07:31
@shanielh

shanielh commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

@alamb thanks for the review, I've modified the code and the "Slow path" now compiles to the same machine code as main, so it shouldn't be slower. And there's more optimizations to run, but I wouldn't put them in this PR.

Edit: Sketched it out in #12460

@shanielh

shanielh commented Dec 2, 2026

Copy link
Copy Markdown
Author

@Jefffrey Anything else before we can this merged? Thanks! 🙏

This branch has not been deployed

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

Labels

parquet parquet crate performance Speed or memory optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants