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 <[email protected]>
|
Hi @dtenedor, I noticed this PR was closed, along with several other performance enhancement PRs you authored. Could you share why? This one, in particular, brings a significant improvement for Parquet files with many dictionary-encoded string columns. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
None.
Rationale for this change
When the
ArrowWriterwrites an Arrow dictionary array of strings or binary, it updates the pagestatistics by comparing every row's value with the running min and max: two
memcmpcalls perrow. With the dictionary cache from #11982, interning is already one lookup per row, so these
comparisons are now most of the cost. In
string_dictionary_low_cardinality_20, a dictionary of 20values,
update_statisticsis 22-24% andmemcmp24-27% of the write.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 the batch's rows use, then compares each referenceddictionary value once. It is used when the dictionary has no more values than the batch has rows:
then some rows must repeat a value, and the pass over the dictionary's flags is no longer than the
batch.
The per-row computation is kept for:
statistic depends on row order
The statistics, and so the file, are unchanged.
Are these changes tested?
A new test writes dictionary arrays of 1 to 100,000 values, with null keys and null values, and
checks that each writes the same file bytes as its values cast to
Utf8. It passes before and afterthis change. Output was also checked to be byte-identical to main's for 288 more dictionary array
files:
Int8,Int16andInt32keysUtf8andBinaryvalues, with duplicate and empty valuesarrow_writerbench, Intel Xeon Platinum 8559C, default x86-64 target, median of 5 alternatingrounds:
arrow_writerbenchstring_dictionary_low_cardinality_20/defaultstring_dictionary_low_cardinality_100/defaultstring_dictionary_low_cardinality_400/defaultparquet_2string_dictionary_1pct_cardinality(10K values, per-row path)string_dictionary(per-row path)string,string_non_null,short_string_non_null(not dictionary arrays)An earlier version used the shortcut for dictionaries up to 16 times the batch. It made
string_dictionary_1pct_cardinality0.61x, because its batches reference nearly 1,024 distinctvalues out of 10,000, and every batch scanned all 10,000 flags. Collecting keys as they are first
seen instead brought that case to 0.87x, but lowered the low-cardinality gains, to 2.13x for 20
values.
Limiting the shortcut to dictionaries no larger than the batch avoids both.
None of the measured inputs got slower. The 0.98x results are on paths this change doesn't affect.
Not measured on aarch64.
Are there any significant user-facing changes?
No.
AI usage disclosure
An AI coding agent (Claude Code) generated the code, the test and this description, and ran the
benchmarks and the output checks. This PR is a draft until the submitter has reviewed it.
This pull request and its description were written by Isaac.