Repository navigation
Conversation
Order the min/max of byte-array statistics by the first 8 bytes of each value as a big-endian u64, which decides most comparisons without a call to memcmp. Values whose first 8 bytes are equal continue in an out-of-line function comparing 8-byte chunks when their common length is at most 64 bytes, and in memcmp when it is longer. Values shorter than 8 bytes use a u64 key built from overlapping loads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
@mbutrovich, thank you, I'm closing this due to your new issue. |
6 tasks
mbutrovich
added a commit
to mbutrovich/arrow-rs
that referenced
this pull request
Nov 30, 2026
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?
This PR makes each byte-array comparison in the per-row min/max statistics cheaper. #12401 makes dictionary arrays run fewer of those comparisons: it folds each dictionary value into the page statistics once per page instead of once per row. The two changes touch different functions (#12401 changes the callers of
is_greater, this PR changesis_greateritself), so they merge in either order. Their gains add up: see "Combined with #12401" below.Rationale for this change
For each row of a
Utf8/Binary/LargeUtf8/LargeBinary/view column, or of a dictionary of those, the arrow writer updates page statistics with two slice comparisons:min > valandval > max. Each one is an out-of-linememcmpcall followed by a length comparison. On random strings this is most of the roughly 97 instructions per row that statistics cost. Most values already differ in their first 8 bytes, and a single integer comparison can order them.What changes are included in this PR?
is_greaterinparquet/src/arrow/arrow_writer/byte_array.rs(non-decimal branch) now callsis_greater_bytes, which handles three cases:u64s. When they differ, which is most rows of most columns, no call is made.as_chunks), then one 8-byte load ending at the shorter value's end. That load starts with bytes already compared equal, so no shift is needed. When the common length is longer than 64 bytes,memcmpis used.u64key is built from overlapping 4-byte loads (or 3 bytes for lengths 1 to 3), followed by a length comparison.There are no public API changes. The new functions (
is_greater_bytes,is_greater_after_prefix,short_key) are private. The column writer'scompare_greater, used bySerializedFileWriterand the arrow writer'sFixedSizeBinarypath, is unchanged. The same change measured −10% instructions on 16-byteFixedSizeBinarythere, which I'd leave to a follow-up.Are these changes tested?
Yes. A new unit test,
is_greater_bytes_matches_slice_order, comparesis_greater_bytes(a, b)witha > bfor every pair from about 1,900 values. Those values cover:0x00,0x7f,0x80and0xff.The existing
arrow_writerstatistics tests andtest_dictionary_array_writes_same_file_as_its_valuescover the written files.Benchmarks
Targeted criterion benchmarks in
parquet/benches/arrow_writer.rs:string,string_dictionary,string_dictionary_low_cardinality_{20,100,400}andstring_dictionary_1pct_cardinality.short_string_non_null.large_string_non_null,small_string_shared_prefixandsmall_string_partial_prefix.These results are instructions and cycles retired per 1M-row write (10 writes minus 0 writes, median of 5 rounds), from a fixed-work program that builds the same batches as those benchmarks and writes them with default properties (dictionary enabled), on an Apple M5 Pro. All four builds in this description (main, this PR, #12401, #12401 + this PR) were measured in one run, alternating builds within each input. Instruction counts repeat within ±0.5% between rounds on most inputs. On inputs with about a million distinct values they move by a few points between runs, because these inputs overflow the dictionary and the interner hashes with a different random seed each run: the 8-byte shared-prefix input has measured −4% to −10% across runs. Instruction counts on the two
small_string_*inputs, about 15M instructions per write, spread ±3% between rounds. The machine had moderate background load during the run, so read cycles as roughly ±10 points.string_dictionarystring_dictionary_low_cardinality_20string_dictionary_low_cardinality_100string_dictionary_low_cardinality_400string_dictionary_1pct_cardinality(value_00000123, 14 bytes)Utf8, 100 random values round-robinUtf8, random 1 to 7 bytesUtf8, 8-byte shared prefix + 4 to 11 random bytesUtf8, 32-byte shared prefix + 4 to 11 random bytesshort_string_non_nulllarge_string_non_null(identical 256 KiB values)large_string_shared_prefix(2 MiB)small_string_shared_prefix(1 KiB, 1016 shared bytes)small_string_partial_prefix(1 KiB, 512 shared bytes)FixedSizeBinary(other code path)With statistics disabled, instructions change by −1.4% to +0.3%.
Combined with #12401
This is this PR applied on top of the #12401 head, compared with the #12401 head alone (same method). #12401 already removes most comparisons for dictionaries with fewer distinct values than rows per page, so the low-cardinality dictionaries gain little more. Plain columns and dictionaries with many distinct values keep the full gain.
string_dictionarystring_dictionary_low_cardinality_20string_dictionary_low_cardinality_100string_dictionary_low_cardinality_400string_dictionary_1pct_cardinality(value_00000123, 14 bytes)Utf8, 100 random values round-robinUtf8, random 1 to 7 bytesUtf8, 8-byte shared prefix + 4 to 11 random bytesUtf8, 32-byte shared prefix + 4 to 11 random bytesshort_string_non_nulllarge_string_non_null(identical 256 KiB values)large_string_shared_prefix(2 MiB)small_string_shared_prefix(1 KiB, 1016 shared bytes)small_string_partial_prefix(1 KiB, 512 shared bytes)FixedSizeBinary(other code path)The
small_string_*rows are within their ±3% spread between rounds. Cycles in thelarge_string_non_nullrow (+6.7%) are noise: its instructions are unchanged, and its per-round cycles range from 115 to 135 for both builds.Which part gives the gain
I measured each part on its own, on top of #12401 except for the 64-byte bound, which was measured on main:
split_first_chunkoras_chunks, is 2–4 points slower on random strings. The chunk split runs before the first comparison.string_dictionary_1pct_cardinalitywas +1.3% instructions. Usingmemcmpon the remaining bytes instead was +11–18% on those inputs.short_keytakes random 1 to 7 byte values from −3.6% to −10%.memcmp.large_string_non_nullwas +22% andsmall_string_shared_prefix+26%. The bound is applied before the call so that the out-of-line function stays a leaf. Bounding inside it gave the function a stack frame and lost the 1pct gain.Slower inputs
Values whose first 8 bytes are equal and whose common length exceeds 64 bytes cost one extra 8-byte comparison before the same
memcmp. Onsmall_string_shared_prefixandsmall_string_partial_prefixthis has measured −0.5% to +0.8% instructions against main across runs, and +2.8% on top of #12401 in the run above. All of these are within the ±3% spread of those two inputs. Columns of long values sharing a long prefix (URLs, paths) hit this. The cost is a few instructions per row against amemcmpof at least 64 bytes.Are there any significant user-facing changes?
No. Statistics and file bytes are unchanged.
AI usage disclosure
Claude Code (Claude Opus 5.5) wrote the implementation and the unit test. It also built and measured the variants listed above under my direction.
🤖 Generated with Claude Code