Repository navigation
Conversation
…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 <no-reply@databricks.com>
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 <noreply@anthropic.com>
f0cf440 to
c58117b
Compare
|
run benchmark arrow_writer |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Benchmark completed (GKE) | trigger Target: arrow_writer Comparing revive-dict-array-statistics (c58117b) to 6747ecd (merge-base) diff Run configurationDetailsPer-runner informationarrow_writer — shard 1/1Node: gk3-benchmark-cluster-nap-iv9lhwbu-d3ef1614-wm5p Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: CPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
run benchmark arrow_writer |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Benchmark completed (GKE) | trigger Target: arrow_writer Comparing revive-dict-array-statistics (c58117b) to 6747ecd (merge-base) diff Run configurationDetailsPer-runner informationarrow_writer — shard 1/1Node: gk3-benchmark-cluster-nap-1xvn17if-a66c6c5a-8rvb Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: CPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Jefffrey Thanks for the review, I've addressed your comments. |
|
ill keep it open for a bit in case others might wanna take a look, cc @Rich-T-kid & @etseidl |
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
ArrowWriterwrites 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: twomemcmpcalls 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?
update_dictionary_statisticsmarks the keys a mini-batch's rows use, then compares each referenced dictionary value once. It is used when the dictionary has no more values than the mini-batch has rows. The per-row computation is kept for larger dictionaries, decimals, geospatial statistics, and a key outside the dictionary. The statistics, and so the file, are unchanged. See perf(parquet): compute dictionary array statistics from the values the rows reference #12282 for the full description and its byte-identical output checks.update_min_maxmade that path +0.50% ± 0.13% instructions onstring_dictionary_1pct_cardinality(a dictionary larger than a mini-batch, where the change otherwise does nothing).#[inline(always)]onupdate_min_maxrestores main's count (−0.02%).Are these changes tested?
The new test from #12282 (dictionary arrays of 1 to 100,000 values, with null keys and null values, written byte-identical to their values cast to
Utf8) and the existingarrow_writertests pass on current main (122 passed).Before / after
arrow_writerbench (string_dictionary*cases), GCPc4a-standard-16spot VM (Google Axion, aarch64, 16 vCPU), Debian 12, rust stable, otherwise idle; median of two alternating rounds per tree (main, PR, main, PR):arrow_writerbench,defaultstring_dictionary_low_cardinality_20string_dictionary_low_cardinality_100string_dictionary_low_cardinality_400string_dictionary_1pct_cardinality(per-row path)string_dictionary(per-row path)The other property sets follow the same pattern: low-cardinality dictionaries are 1.83x to 2.81x faster with
bloom_filter,parquet_2,zstdandzstd_parquet_2, 1.69x to 2.18x withcdc, and 1.19x to 1.27x withnumber_distinct_values; the per-row cases are 1.00x to 1.01x.All 35 cases
arrow_writerbenchstring_dictionary_low_cardinality_20/defaultstring_dictionary_low_cardinality_20/bloom_filterstring_dictionary_low_cardinality_20/parquet_2string_dictionary_low_cardinality_20/zstdstring_dictionary_low_cardinality_20/zstd_parquet_2string_dictionary_low_cardinality_20/cdcstring_dictionary_low_cardinality_20/number_distinct_valuesstring_dictionary_low_cardinality_100/defaultstring_dictionary_low_cardinality_100/bloom_filterstring_dictionary_low_cardinality_100/parquet_2string_dictionary_low_cardinality_100/zstdstring_dictionary_low_cardinality_100/zstd_parquet_2string_dictionary_low_cardinality_100/cdcstring_dictionary_low_cardinality_100/number_distinct_valuesstring_dictionary_low_cardinality_400/defaultstring_dictionary_low_cardinality_400/bloom_filterstring_dictionary_low_cardinality_400/parquet_2string_dictionary_low_cardinality_400/zstdstring_dictionary_low_cardinality_400/zstd_parquet_2string_dictionary_low_cardinality_400/cdcstring_dictionary_low_cardinality_400/number_distinct_valuesstring_dictionary_1pct_cardinality/defaultstring_dictionary_1pct_cardinality/bloom_filterstring_dictionary_1pct_cardinality/parquet_2string_dictionary_1pct_cardinality/zstdstring_dictionary_1pct_cardinality/zstd_parquet_2string_dictionary_1pct_cardinality/cdcstring_dictionary_1pct_cardinality/number_distinct_valuesstring_dictionary/defaultstring_dictionary/bloom_filterstring_dictionary/parquet_2string_dictionary/zstdstring_dictionary/zstd_parquet_2string_dictionary/cdcstring_dictionary/number_distinct_valuesstring_dictionary_1pct_cardinality/cdcread 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 was also measured by retired instructions 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) and writes each one 10 times to an empty sink with the bench's writer properties; the write cost is the instruction count of 10 writes minus that of 0. Counts repeat within about ±0.3% run to run.
defaultstring_dictionary_low_cardinality_20string_dictionary_low_cardinality_100string_dictionary_low_cardinality_400string_dictionary_1pct_cardinalitystring_dictionaryThis is how the per-row regression fixed by the second commit was found: +0.50% ± 0.13% on
string_dictionary_1pct_cardinality(10 alternating rounds) before it, −0.02% after.Where the gain comes from, and random keys
The gain is the per-row statistics comparisons that the dictionary path no longer makes: the min and max are folded over the referenced dictionary values instead, after one pass that marks which keys the rows use. Inputs that take the per-row path (
string_dictionary_1pct_cardinality,string_dictionary) are unchanged, so the rest of the change costs nothing measurable.The
low_cardinalitybenches pick keys round-robin, so the same measurement was repeated with random keys, and at the boundary where the path is taken: a dictionary as large as a mini-batch (write_batch_size, 1024). Retired instructions and cycles per write, same machine and method as above (cycles: median of five alternating rounds):defaultlow_cardinality_400, round-robin keysNo input measured slower. The gain is smallest when the dictionary is about as large as a mini-batch and the rows reference most of it, because the marking pass and the fold then touch about as many values as there are rows; a larger dictionary takes the per-row path.
A production workload
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.
🤖 Generated with Claude Code