Skip to content

perf(parquet): cache a dictionary shared by consecutive writes - #12532

Open
shanielh wants to merge 2 commits into
apache:mainfrom
shanielh:parquet-cache-repeated-dictionary
Open

shanielh wants to merge 2 commits into
apache:mainfrom
shanielh:parquet-cache-repeated-dictionary

Conversation

@shanielh

@shanielh shanielh commented Dec 2, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

The byte array dictionary encoder caches each arrow dictionary value's interned index, so a value is hashed once rather than once per row (#11982). It starts that cache only when one write references at least as many rows as the dictionary has values (#12122).

A dictionary with more values than any one write has rows, shared by the writes that follow, never gets a cache: every row is hashed into the interner. That is the shape a reader produces when it keeps one dictionary across batches, for example slices of one dictionary column, or the batches of an external sort whose runs share a dictionary.

What changes are included in this PR?

  • Rows encoded without the cache now count toward the same threshold, for as long as consecutive writes carry the same dictionary allocation. Rows are counted per call, so a write split into several calls by write_batch_size or the page limit counts its rows once. A different dictionary in between starts the count again. A single write decides exactly as before.
  • The cache keeps its existing cost, one u64 per dictionary value per column chunk, and still starts only once at least that many rows have referenced the dictionary.
  • A benchmark, string_dictionary_shared_by_batches, as the first commit: 256 batches of 4,096 rows, slices of one Dictionary<Int32, Utf8> column whose dictionary has 32,768 values.

Are these changes tested?

Yes. use_dictionary_cache_dictionary_shared_by_writes covers a dictionary shared by consecutive writes, a write split into several calls, and another dictionary in between. The two existing cache tests are updated for the new signature and keep their cases.

arrow_writer benchmarks on an Apple M-series laptop: the cases #11982 reported, plus the new string_dictionary_shared_by_batches. "main" is this PR's first commit (main plus the benchmark); each side ran on an otherwise idle machine.

Benchmark main (ms) this PR (ms) Change
string/default 52.70 51.29 -2.7%
string/parquet_2 61.59 61.26 -0.5%
string_dictionary/default 25.94 25.89 -0.2%
string_dictionary/parquet_2 30.46 30.11 -1.2%
string_dictionary_low_cardinality_100/default 7.39 7.19 -2.7%
string_dictionary_low_cardinality_100/parquet_2 7.31 7.14 -2.3%
string_non_null/default 58.11 56.70 -2.4%
string_non_null/parquet_2 72.96 70.94 -2.8%
string_ree_of_dict/default 18.69 18.69 -0.0%
string_ree_of_dict/parquet_2 18.58 18.68 +0.5%
string_dictionary_shared_by_batches/default 16.99 9.42 -44.6%

Only the last case writes one dictionary across several writes. The other cases take the same path as before, so their differences of up to 3% are run-to-run variance (the string_non_null cases have no dictionary column at all).

Are there any significant user-facing changes?

No. The encoded output is unchanged: the cached path interns each value at the first row that references it, as the uncached path does.

AI usage disclosure

Claude (Anthropic) helped find the cause, write the change, its tests and the benchmark, and draft this description. I reviewed and ran all of it.

🤖 Generated with Claude Code

shanielh and others added 2 commits December 2, 2026 08:31
Adds `string_dictionary_shared_by_batches`: 256 batches of 4,096 rows, slices
of one dictionary column whose dictionary has 32,768 values, more than any
one batch has rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The byte array dictionary encoder starts a dictionary cache only when one
write references at least as many rows as the dictionary has values. A
dictionary larger than each write, but shared by the writes that follow,
never got one, and every row was hashed into the interner.

Rows encoded without the cache now count toward that threshold while
consecutive writes carry the same dictionary allocation. A single write
decides as before.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant