Repository navigation
fix(parquet): keep DELTA_BYTE_ARRAY dedup for values larger than the page size limit - #10505
Conversation
|
run benchmark arrow_writer |
|
run benchmark writer_overhead |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing fix-delta-byte-array-page-split-10489 (d053bf0) to cd17899 (merge-base) diff Run configurationrun benchmark arrow_writerBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writer File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing fix-delta-byte-array-page-split-10489 (d053bf0) to cd17899 (merge-base) diff Run configurationrun benchmark writer_overheadBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench writer_overhead File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-delta-byte-array-page-split-10489 (d053bf0) to cd17899 (merge-base) diff Run configurationrun benchmark writer_overheadCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-delta-byte-array-page-split-10489 (d053bf0) to cd17899 (merge-base) diff Run configurationrun benchmark arrow_writerCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
d63a6d7 to
5b904cc
Compare
…er benchmark (#10512) # Which issue does this PR close? - Part of #10511 # Rationale for this change No existing benchmark writes `DELTA_BYTE_ARRAY` through the writer: the `arrow_writer` property matrix varies writer version, compression, bloom filters, and CDC, all on the default encoding, and `encoding.rs` benches encoders in isolation. That gap matters for the large-value write path specifically: the byte-budget sub-batching in `write_batch_internal` (#9972) measures raw payload bytes, and page-boundary behavior interacts with the encoding's cross-value state (#10489, #10505). None of that is visible to any current benchmark. #10511 tracks whether making the byte budget encoded-size-aware is worthwhile; these benchmarks are the measurement for that question. # What changes are included in this PR? Two new batches and one new bench group in `parquet/benches/arrow_writer.rs`: - `large_string_shared_prefix`: 128 rows x 2 MiB, long common prefix with a short distinct suffix (the case `DELTA_BYTE_ARRAY` exists for) - `large_string_distinct`: same shape, values differing from byte 0 (the adversarial case, prefix length ~0) Values are sized so one value alone exceeds the default 1 MiB page limit, the regime of #10489. Each batch runs under `plain` and `delta_byte_array` properties (dictionary disabled), so the delta-vs-plain gap on identical data separates inherent encoding cost from writer overhead. Results on an Apple M-series laptop, current `main`: | group | `plain` | `delta_byte_array` | | --- | --- | --- | | `large_string_shared_prefix` | 59.0 ms (4.2 GiB/s) | 61.4 ms (4.1 GiB/s) | | `large_string_distinct` | 37.2 ms (6.7 GiB/s) | 44.7 ms (5.6 GiB/s) | Note these numbers shift when #10505 lands, in both directions: shared-prefix delta gets slower in CPU time because the encoder starts doing real prefix comparisons instead of degenerating to per-page `PLAIN` (while the output shrinks ~128x), and distinct delta gets faster from halving the page count. That sensitivity is the point of having the benchmark. # Are these changes tested? The change is itself a benchmark; it compiles and runs under `cargo bench -p parquet --bench arrow_writer`. # Are there any user-facing changes? No. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5 <[email protected]>
5b904cc to
c284081
Compare
|
run benchmark arrow_writer writer_overhead |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark arrow_writerBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writer File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark writer_overheadBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench writer_overhead File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark writer_overheadCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark arrow_writerCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
run benchmark arrow_writer writer_overhead |
1 similar comment
|
run benchmark arrow_writer writer_overhead |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark writer_overheadBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench writer_overhead File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark arrow_writerBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writer File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark arrow_writerBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writer File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark writer_overheadBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench writer_overhead File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark writer_overheadCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark writer_overheadCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark arrow_writerCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-delta-byte-array-page-split-10489 (c284081) to f8a57f8 (merge-base) diff Run configurationrun benchmark arrow_writerCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
…ounts `byte_budget_sub_batch_size` asks the encoder how many *values* fit in a page byte budget, then converts that to a *level* count using the chunk-wide level:value ratio, rounded up. For a chunk with no nulls that is exact. With one null in 17 levels it gives `ceil(17/16) == 2`, and `write_granular_chunk` slices the chunk into uniform two-level windows — most of which carry two values, twice what the budget allowed. The mechanism dates to apache#9972; apache#10505 raises its cost but does not introduce it. Where the encoding compresses a value against its predecessor, that round-up costs whole values of output. 128 values of 2 MiB at one null in 16 write 16.78 MB instead of 2.10 MB; at 8 MiB values it is 64 MiB instead of 8 MiB. Have the chunker return the value count it already computed, and let `write_granular_chunk` end a window by walking definition levels until it has covered that many values. Apply it only where it changes the bytes written, because it roughly doubles the mini-batch count on a nullable column. Two conditions: - The budget must be the data page budget, a constant `data_page_size_limit`, so a one-value budget means the value itself overflows a page. The dictionary page budget is the limit minus what the dictionary already holds, so it shrinks toward zero and reaches a one-value budget on ordinary values; cutting exactly there measured +13.0% on `string/default` and +8.3% on `string/parquet_2`. - The encoding must compress against the previous value. `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` store a value identically wherever it lands, so value-exact windows leave their output byte for byte the same while doubling the page count — +27.6% on a nullable column for no reduction in output. What the other paths give up is bounded. A ratio-scaled window spans `ceil(values * levels / values_in_chunk)` levels, covering at most two values where one already fills the budget, whatever the null density, and exactly one wherever the ratio is a whole number. Against a 1 MiB limit that is a 4 MiB page for 2 MiB values rather than 2 MiB — and 2 MiB is the floor, since a page must hold a value. It does not scale with `write_batch_size`, which is the failure apache#9972 fixed. `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup` is re-pinned from `[2, 2, 2, 2, 9]` to `[17]` and renamed, the layout apache#10505 left a marker for. `test_column_writer_caps_page_size_with_sparse_nulls` pins two values per page under `PLAIN`, so it fails both if the encoding gate is dropped and if the bound is lost. Closes apache#10538
alamb
left a comment
There was a problem hiding this comment.
Thank you @adriangb .I went over the code carefully and I think it is ok to merge as is
However I left a bunch of comments about how to make this PR more concise (removing extraneous comments) and the name of a field.
I do feel like this is some non trivial complexity for a pretty niche corner case (encoding many exactly repeated long strings 🤔 , but I suppose that does happen in tests, etc)
| fn has_dictionary(&self) -> bool; | ||
|
|
||
| /// Returns true if the encoder compresses each value against the value | ||
| /// before it *within the current page* — today, `DELTA_BYTE_ARRAY` and |
There was a problem hiding this comment.
I found the mention of DELTA_BYTE_ARRAY confusing here as it appears to come out of the blue -- maybe it can be listed at the bottom of the comment with PLAIN and DELTA_LENGTH_BYTE_ARRAY
| /// | ||
| /// For such encodings a page boundary is not free: flushing discards the | ||
| /// previous value, so the first value of the next page is stored in full. | ||
| /// A column of large values that share long prefixes therefore collapses |
There was a problem hiding this comment.
the mention of large values / shared prefixes seems like a detail of DELTA_BYTE_ARRAY -- the first sentence of this comment is probably enough
| /// A column of large values that share long prefixes therefore collapses | ||
| /// to `PLAIN` if every value is cut into its own page. The column writer | ||
| /// uses this to exempt a page's mandatory first value from the data page | ||
| /// byte limit; see `should_add_data_page`. |
There was a problem hiding this comment.
If we are going to link to something can it please be a full on Rustdoc link (e.g.
[foo]| /// uses this to exempt a page's mandatory first value from the data page | ||
| /// byte limit; see `should_add_data_page`. | ||
| /// | ||
| /// Defaults to `false`: for `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` a |
There was a problem hiding this comment.
again here it seems like the mention of PLAIN and DELTA_BYTE_ARRAY is out of the blue (as in why not also include something about DICT encoding too...
Maybe we could just simplify this comment to to say
/// Returns true if the encoder compresses each value against the value
/// before it *within the current page*.
///
/// Used for encodings such as `DELTA_BYTE_ARRAY` where
/// a page boundary is not free: flushing discards the
/// previous value, so the first value of the next page is stored in full.
/// The column writer
/// uses this to exempt a page's mandatory first value from the data page
/// byte limit; see [`should_add_data_page`].
| .set_statistics_enabled(EnabledStatistics::None) | ||
| .build(); | ||
|
|
||
| // Each value differs from byte 0, so every prefix length is 0. |
There was a problem hiding this comment.
each value differs from the previous value? Not sure what byte zero means
| let total_bytes: usize = pages.data_pages.iter().map(|(size, _)| size).sum(); | ||
| assert!( | ||
| total_bytes < 2 * value_size, | ||
| "expected ~one value's worth of bytes for {num_rows} identical values, \ |
There was a problem hiding this comment.
What does it mean "one value's worth of bytes" -- the check is that the encoding reduces the size to be 2x the size of a single value
According to claude The ideal output for 16 identical values is one value stored in full plus 15 zero-length suffixes -- perhaps that would be clearer to say explictly / in comments
| let total_values: u32 = pages.data_pages.iter().map(|(_, n)| n).sum(); | ||
| assert_eq!(total_values as usize, num_rows); | ||
|
|
||
| // The exempted first value plus one more that trips the budget: at |
There was a problem hiding this comment.
ah! here it even already uses the term exempted !
| // The exemption fires when a page's first mini-batch contains exactly | ||
| // one value. For a non-nullable column the byte-budget chunker gives | ||
| // an over-limit value a one-level mini-batch, so that always holds. | ||
| // One null in the chunk changes the level:value ratio to 17:16, the |
There was a problem hiding this comment.
this is a lot of detail of the internal working of the encoder -- maybe we can just trim this down to explain what the actual problem is (page size is too large) and the conditions needed to trigger it (a single null mini batch?)
| // | ||
| // Same shape as `test_large_string` — 64 KiB values against a 16 KiB | ||
| // page limit — but `DELTA_BYTE_ARRAY` and identical values. Cutting one | ||
| // page per value would reset the encoder's shared-prefix state every |
There was a problem hiding this comment.
again woudl recommend removing the implementation details and focus on what data is expected here -- namely that it should be possible to get all 32 values on the page, even though it is over the page budget
…page limit A `BYTE_ARRAY` value larger than `data_page_size_limit` exceeds the limit on its own, so the post-write `should_add_data_page` check cuts a page after every single value. Parquet requires at least one value per data page, so that value is unsplittable and the limit is simply unsatisfiable there. For `DELTA_BYTE_ARRAY` this is destructive rather than merely wasteful: each page boundary discards the encoder's previous value, so every value gets `prefix_length = 0` and the encoding degenerates to exactly `PLAIN`. Columns of large values that share long prefixes stop being deduplicated (apache#10489). Exempt a page's mandatory first value from the byte limit when that value alone already exceeds it, so the limit applies to what follows — the bytes we can still place on another page. The exemption is gated on `ColumnValueEncoder::compresses_against_previous_value`, so only `DELTA_BYTE_ARRAY` opts in; `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` cost the same wherever a value lands and keep their existing one-value page bound. Pages therefore stay bounded by the value size rather than growing with `write_batch_size`, preserving the fix from apache#9972. Dedup stays partial on nullable columns, and `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup` pins that as a documented limitation rather than an accident. The exemption triggers on a page-opening mini-batch holding exactly one value. A null in a chunk changes the level:value ratio, the byte-budget chunker rounds up to two-level mini-batches, and pages that open with a two-value mini-batch miss the exemption: they are cut after two values with the first stored in full. The mini-batch pairing the null with a value has one value, so the page it opens does get the exemption and accumulates the remaining suffixes. That layout ([2, 2, 2, 2, 9] for 16 identical values with a null at index 8) is pinned, and noted on `set_page_size_floor`; apache#10538 tracks lifting it. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
…tion Documentation-only follow-up to the review: - Rewrite `ColumnValueEncoder::compresses_against_previous_value` so the behavior comes first and the per-encoding breakdown is listed at the end, rather than naming DELTA_BYTE_ARRAY up front. - Turn the bare `should_add_data_page` references into intra-doc links so the docs job catches them if they go stale. - Rename `PageMetrics::page_size_floor` to `page_size_exemption` (and `set_page_size_floor` to `set_page_size_exemption`) to match the term the tests already use. - Trim encoder internals out of the test comments and describe the input and expected layout instead; state the actual bound in the dedup assertion message. No behavior change. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_01JYwFB2SU1Y1LCg5c5HJVq9
bd99e79 to
b38ee51
Compare
|
Thanks @alamb, I incorporated your feedback. |
…ounts `byte_budget_sub_batch_size` asks the encoder how many *values* fit in a page byte budget, then converts that to a *level* count using the chunk-wide level:value ratio, rounded up. For a chunk with no nulls that is exact. With one null in 17 levels it gives `ceil(17/16) == 2`, and `write_granular_chunk` slices the chunk into uniform two-level windows — most of which carry two values, twice what the budget allowed. The mechanism dates to apache#9972; apache#10505 raises its cost but does not introduce it. Where the encoding compresses a value against its predecessor, that round-up costs whole values of output. 128 values of 2 MiB at one null in 16 write 16.78 MB instead of 2.10 MB; at 8 MiB values it is 64 MiB instead of 8 MiB. Have the chunker return the value count it already computed, and let `write_granular_chunk` end a window by walking definition levels until it has covered that many values. Apply it only where it changes the bytes written, because it roughly doubles the mini-batch count on a nullable column. Two conditions: - The budget must be the data page budget, a constant `data_page_size_limit`, so a one-value budget means the value itself overflows a page. The dictionary page budget is the limit minus what the dictionary already holds, so it shrinks toward zero and reaches a one-value budget on ordinary values; cutting exactly there measured +13.0% on `string/default` and +8.3% on `string/parquet_2`. - The encoding must compress against the previous value. `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` store a value identically wherever it lands, so value-exact windows leave their output byte for byte the same while doubling the page count — +27.6% on a nullable column for no reduction in output. What the other paths give up is bounded. A ratio-scaled window spans `ceil(values * levels / values_in_chunk)` levels, covering at most two values where one already fills the budget, whatever the null density, and exactly one wherever the ratio is a whole number. Against a 1 MiB limit that is a 4 MiB page for 2 MiB values rather than 2 MiB — and 2 MiB is the floor, since a page must hold a value. It does not scale with `write_batch_size`, which is the failure apache#9972 fixed. `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup` is re-pinned from `[2, 2, 2, 2, 9]` to `[17]` and renamed, the layout apache#10505 left a marker for. `test_column_writer_caps_page_size_with_sparse_nulls` pins two values per page under `PLAIN`, so it fails both if the encoding gate is dropped and if the bound is lost. Closes apache#10538
…larger than the page size limit (#10826) # Which issue does this PR close? - part of #10738 # Rationale for this change Backport the fix for the DELTA_BYTE_ARRAY dedup regression with values larger than the page size limit (#10489) to the `59_maintenance` branch so it is included in the 59.3.0 release. # What changes are included in this PR? Backport / Cherry-pick: - #10505 # Are these changes tested? By CI # Are there any user-facing changes? No Co-authored-by: Adrian Garcia Badaracco <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
…ounts `byte_budget_sub_batch_size` asks the encoder how many *values* fit in a page byte budget, then converts that to a *level* count using the chunk-wide level:value ratio, rounded up. For a chunk with no nulls that is exact. With one null in 17 levels it gives `ceil(17/16) == 2`, and `write_granular_chunk` slices the chunk into uniform two-level windows — most of which carry two values, twice what the budget allowed. The mechanism dates to apache#9972; apache#10505 raises its cost but does not introduce it. Where the encoding compresses a value against its predecessor, that round-up costs whole values of output. 128 values of 2 MiB at one null in 16 write 16.78 MB instead of 2.10 MB; at 8 MiB values it is 64 MiB instead of 8 MiB. Have the chunker return the value count it already computed, and let `write_granular_chunk` end a window by walking definition levels until it has covered that many values. Apply it only where it changes the bytes written, because it roughly doubles the mini-batch count on a nullable column. Two conditions: - The budget must be the data page budget, a constant `data_page_size_limit`, so a one-value budget means the value itself overflows a page. The dictionary page budget is the limit minus what the dictionary already holds, so it shrinks toward zero and reaches a one-value budget on ordinary values; cutting exactly there measured +13.0% on `string/default` and +8.3% on `string/parquet_2`. - The encoding must compress against the previous value. `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` store a value identically wherever it lands, so value-exact windows leave their output byte for byte the same while doubling the page count — +27.6% on a nullable column for no reduction in output. What the other paths give up is bounded. A ratio-scaled window spans `ceil(values * levels / values_in_chunk)` levels, covering at most two values where one already fills the budget, whatever the null density, and exactly one wherever the ratio is a whole number. Against a 1 MiB limit that is a 4 MiB page for 2 MiB values rather than 2 MiB — and 2 MiB is the floor, since a page must hold a value. It does not scale with `write_batch_size`, which is the failure apache#9972 fixed. `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup` is re-pinned from `[2, 2, 2, 2, 9]` to `[17]` and renamed, the layout apache#10505 left a marker for. `test_column_writer_caps_page_size_with_sparse_nulls` pins two values per page under `PLAIN`, so it fails both if the encoding gate is dropped and if the bound is lost. Closes apache#10538
…ache#10745) - Follow-up to apache#10505 / apache#10554 (independent of both; apache#10554 is now stacked on top of this) ## What `compute_min_max` in `arrow_writer/byte_array.rs` copies both the minimum and the maximum of every mini-batch into fresh `ByteArray`s (`to_vec()`) before `encode` has checked whether either one beats the running page min/max. `write_gather` runs once per mini-batch, and a byte-budgeted mini-batch of large values can hold a single value — so every large value was being allocated and copied twice more, on top of the copies the encoder itself needs. This returns the borrowed extremes and copies only when the running value actually changes. Statistics are unchanged; the comparison is the same byte-lexicographic order `ByteArray` uses. It only ever removes copies, so it cannot cost more anywhere. ## Why now Found while profiling apache#10554 (value-exact mini-batch windows), which showed **+12…15%** on `large_string_distinct_nullable/delta_byte_array` across three runner runs against both `main` and apache#10505. `samply` put the whole shift into `memmove` under `ByteArrayEncoder::write_gather`; the encoding work per value is identical, so the cost had to be per-mini-batch — and apache#10554 roughly doubles the mini-batch count on nullable columns. That was this copy. ## Measurements Runner (`c4a-highmem-16`), three runs each way with identical-code controls; full tables and links in the [results comment](apache#10745 (comment)). Isolated (stacked on apache#10554, vs apache#10554 head): | benchmark | mean of 3 | control | |---|---|---| | `large_string_shared_prefix_nullable/delta_byte_array` | **−24.4%** | +0.8 | | `large_string_shared_prefix_nullable_trailing/delta_byte_array` | **−23.2%** | −0.2 | | `large_string_shared_prefix_nullable_dense/delta_byte_array` | **−22.0%** | +0.7 | | `large_string_shared_prefix/delta_byte_array` (non-null) | **−21.9%** | −0.7 | | `medium_string_shared_prefix_nullable/delta_byte_array` | −7.2% | +4.9 | | `large_string_distinct_nullable/delta_byte_array` | −5.4% | −0.8 | | `large_string_distinct/delta_byte_array` | −4.0% | −0.2 | Effect on apache#10554's regression: `large_string_distinct_nullable/delta_byte_array` vs apache#10505 goes from **+14.7% to +5.4%**, and its `_nullable` shape from +18.3% to −13.6%. Alone, vs `main`: the over-limit `DELTA_BYTE_ARRAY` benches are flat — there every over-limit value already opens its own page (the bug apache#10505 fixes), so `flush_data_page` takes the running min/max on every mini-batch and both copies happen regardless. `large_string_non_null/*` (1024 × 256 KiB, default properties) is **−7…−9%** in all three full runs with a flat control, so it pays today wherever a page holds more than one mini-batch of large values. Nothing else moves outside what the main-vs-main control moves on identical code. ## Tests No behaviour change; full `parquet` suite green, `fmt` and `clippy -D warnings` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
…ache#10745) - Follow-up to apache#10505 / apache#10554 (independent of both; apache#10554 is now stacked on top of this) ## What `compute_min_max` in `arrow_writer/byte_array.rs` copies both the minimum and the maximum of every mini-batch into fresh `ByteArray`s (`to_vec()`) before `encode` has checked whether either one beats the running page min/max. `write_gather` runs once per mini-batch, and a byte-budgeted mini-batch of large values can hold a single value — so every large value was being allocated and copied twice more, on top of the copies the encoder itself needs. This returns the borrowed extremes and copies only when the running value actually changes. Statistics are unchanged; the comparison is the same byte-lexicographic order `ByteArray` uses. It only ever removes copies, so it cannot cost more anywhere. ## Why now Found while profiling apache#10554 (value-exact mini-batch windows), which showed **+12…15%** on `large_string_distinct_nullable/delta_byte_array` across three runner runs against both `main` and apache#10505. `samply` put the whole shift into `memmove` under `ByteArrayEncoder::write_gather`; the encoding work per value is identical, so the cost had to be per-mini-batch — and apache#10554 roughly doubles the mini-batch count on nullable columns. That was this copy. ## Measurements Runner (`c4a-highmem-16`), three runs each way with identical-code controls; full tables and links in the [results comment](apache#10745 (comment)). Isolated (stacked on apache#10554, vs apache#10554 head): | benchmark | mean of 3 | control | |---|---|---| | `large_string_shared_prefix_nullable/delta_byte_array` | **−24.4%** | +0.8 | | `large_string_shared_prefix_nullable_trailing/delta_byte_array` | **−23.2%** | −0.2 | | `large_string_shared_prefix_nullable_dense/delta_byte_array` | **−22.0%** | +0.7 | | `large_string_shared_prefix/delta_byte_array` (non-null) | **−21.9%** | −0.7 | | `medium_string_shared_prefix_nullable/delta_byte_array` | −7.2% | +4.9 | | `large_string_distinct_nullable/delta_byte_array` | −5.4% | −0.8 | | `large_string_distinct/delta_byte_array` | −4.0% | −0.2 | Effect on apache#10554's regression: `large_string_distinct_nullable/delta_byte_array` vs apache#10505 goes from **+14.7% to +5.4%**, and its `_nullable` shape from +18.3% to −13.6%. Alone, vs `main`: the over-limit `DELTA_BYTE_ARRAY` benches are flat — there every over-limit value already opens its own page (the bug apache#10505 fixes), so `flush_data_page` takes the running min/max on every mini-batch and both copies happen regardless. `large_string_non_null/*` (1024 × 256 KiB, default properties) is **−7…−9%** in all three full runs with a flat control, so it pays today wherever a page holds more than one mini-batch of large values. Nothing else moves outside what the main-vs-main control moves on identical code. ## Tests No behaviour change; full `parquet` suite green, `fmt` and `clippy -D warnings` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
…page size limit (apache#10505) - closes apache#10489 - closes apache#10504 ## The cause is the page flush, not the mini-batch splitting The issue attributes the regression to apache#9972's byte-budget sub-batching. It's actually the page flush; the sub-batching only exposes it. `should_add_data_page` fires when `estimated_data_page_size() >= data_page_size_limit`. For `DELTA_BYTE_ARRAY` that estimate is the real encoded size, and the first value on a page is stored in full — so a single 8 MiB value against a 1 MiB limit puts the page over the limit by itself and triggers a flush. Flushing clears the encoder's `previous`, so the next value gets `prefix_length = 0`, and so on. The encoding degenerates to exactly `PLAIN`. Before apache#9972 a 1024-row mini-batch meant the check simply didn't run until 1024 values had been written, so the dedup survived. That was an accident of `write_batch_size`, not a designed property — the same column at 2000 rows already lost the prefix at the 1024-value boundary. This matters for choosing a fix: **making the byte budget encoding-aware (suggestion 2 in the issue) does not fix the reported bug.** However precise the budget, the first value alone still exceeds the limit and still triggers the flush. ## The fix Parquet requires at least one value per data page, so a value larger than the limit cannot be split out — the limit is unsatisfiable for it. Counting those bytes against the limit is what forces the pathological one-value-per-page cut. Record that first value's encoded size in `PageMetrics::page_size_floor` and apply the limit to what follows it, i.e. the bytes that *can* still go on another page. The exemption is gated on a new `ColumnValueEncoder::compresses_against_previous_value` (default `false`, `true` only for `DELTA_BYTE_ARRAY` in both the generic and arrow encoders). `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` cost the same wherever a value lands, so there is nothing to preserve by keeping values together and they keep their existing tighter one-value page bound. All three regression tests from apache#9972 pass unmodified. ## Why not "don't split when the split cannot help" Suggestion 1 in the issue restores the dedup, but by removing the bound that apache#9972 added, for exactly the workload it was added for. Measured with `Some(1) => chunk_size` in `byte_budget_chunker.rs`, 2048 rows × 128 KiB distinct values against a 64 KiB page limit — the same regime as a 10 MB value against the 1 MiB default, scaled to fit in RAM: | | pages | max page | |---|---|---| | 59.1.0 | 2048 | 128 KiB | | suggestion 1 | 2 | **128 MiB** | | this PR | 1024 | 256 KiB | Page size under suggestion 1 is `write_batch_size × value_size`. At 1024 × 10 MB that is a 10 GB page, which is the failure apache#9972 fixed. ## Results The reporter's table, reproduced verbatim (10 identical 8 MiB values, raw input 80 MiB): | `data_page_size_limit` | 58.4.0 | 59.1.0 | this PR | | --- | --- | --- | --- | | default (1 MiB) | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 4 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 8 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 16 MiB | 8.00 MiB | 8.00 MiB | **8.00 MiB** | Values that merely share a long prefix behave the same. Values sharing *no* prefix are unaffected in file size and stay bounded at up to two values per page — the exempt one plus the one that trips the budget. ## Tests - `test_column_writer_delta_byte_array_dedups_large_shared_prefix_values` — 16 identical 64 KiB values, 16 KiB page limit. Fails on `main` with 1 MiB across 16 pages (byte for byte what `PLAIN` produces); passes here at ~one value's worth. - `test_column_writer_delta_byte_array_bounds_pages_without_shared_prefix` — the same column with values differing from byte 0, asserting pages stay bounded by two values. Guards against fixing this by dropping the bound. - `test_large_string_delta_byte_array_shared_prefix` — the `ArrowWriter` path from the report, as an exact page-layout assertion. ## Notes One known limitation, pinned by `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup`: the exemption triggers when a page opens with a mini-batch holding exactly one value. That is guaranteed for chunks without nulls (the byte-budget chunker gives an over-limit value its own mini-batch), but a null in a chunk makes the chunker convert values to levels by ratio and round up, so pages can open with a two-value mini-batch, miss the exemption, and store their first value in full. Dedup on such columns is partial rather than absent, and never worse than `main`, which stores every value in full. The clean fix is for the granular path to cut windows after an exact value count instead of ratio-scaling; that is independent of this change and tracked in apache#10538. The pinning test documents the layout to expect once it lands. A follow-up worth considering separately: the byte budget in `count_within_budget_*` still measures raw payload length, so `DELTA_BYTE_ARRAY` columns sub-batch more eagerly than the encoded size warrants. That is a throughput question rather than a correctness one, and it is not what caused this regression. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <[email protected]>
…ache#10745) - Follow-up to apache#10505 / apache#10554 (independent of both; apache#10554 is now stacked on top of this) ## What `compute_min_max` in `arrow_writer/byte_array.rs` copies both the minimum and the maximum of every mini-batch into fresh `ByteArray`s (`to_vec()`) before `encode` has checked whether either one beats the running page min/max. `write_gather` runs once per mini-batch, and a byte-budgeted mini-batch of large values can hold a single value — so every large value was being allocated and copied twice more, on top of the copies the encoder itself needs. This returns the borrowed extremes and copies only when the running value actually changes. Statistics are unchanged; the comparison is the same byte-lexicographic order `ByteArray` uses. It only ever removes copies, so it cannot cost more anywhere. ## Why now Found while profiling apache#10554 (value-exact mini-batch windows), which showed **+12…15%** on `large_string_distinct_nullable/delta_byte_array` across three runner runs against both `main` and apache#10505. `samply` put the whole shift into `memmove` under `ByteArrayEncoder::write_gather`; the encoding work per value is identical, so the cost had to be per-mini-batch — and apache#10554 roughly doubles the mini-batch count on nullable columns. That was this copy. ## Measurements Runner (`c4a-highmem-16`), three runs each way with identical-code controls; full tables and links in the [results comment](apache#10745 (comment)). Isolated (stacked on apache#10554, vs apache#10554 head): | benchmark | mean of 3 | control | |---|---|---| | `large_string_shared_prefix_nullable/delta_byte_array` | **−24.4%** | +0.8 | | `large_string_shared_prefix_nullable_trailing/delta_byte_array` | **−23.2%** | −0.2 | | `large_string_shared_prefix_nullable_dense/delta_byte_array` | **−22.0%** | +0.7 | | `large_string_shared_prefix/delta_byte_array` (non-null) | **−21.9%** | −0.7 | | `medium_string_shared_prefix_nullable/delta_byte_array` | −7.2% | +4.9 | | `large_string_distinct_nullable/delta_byte_array` | −5.4% | −0.8 | | `large_string_distinct/delta_byte_array` | −4.0% | −0.2 | Effect on apache#10554's regression: `large_string_distinct_nullable/delta_byte_array` vs apache#10505 goes from **+14.7% to +5.4%**, and its `_nullable` shape from +18.3% to −13.6%. Alone, vs `main`: the over-limit `DELTA_BYTE_ARRAY` benches are flat — there every over-limit value already opens its own page (the bug apache#10505 fixes), so `flush_data_page` takes the running min/max on every mini-batch and both copies happen regardless. `large_string_non_null/*` (1024 × 256 KiB, default properties) is **−7…−9%** in all three full runs with a flat control, so it pays today wherever a page holds more than one mini-batch of large values. Nothing else moves outside what the main-vs-main control moves on identical code. ## Tests No behaviour change; full `parquet` suite green, `fmt` and `clippy -D warnings` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
…page size limit (apache#10505) - closes apache#10489 - closes apache#10504 ## The cause is the page flush, not the mini-batch splitting The issue attributes the regression to apache#9972's byte-budget sub-batching. It's actually the page flush; the sub-batching only exposes it. `should_add_data_page` fires when `estimated_data_page_size() >= data_page_size_limit`. For `DELTA_BYTE_ARRAY` that estimate is the real encoded size, and the first value on a page is stored in full — so a single 8 MiB value against a 1 MiB limit puts the page over the limit by itself and triggers a flush. Flushing clears the encoder's `previous`, so the next value gets `prefix_length = 0`, and so on. The encoding degenerates to exactly `PLAIN`. Before apache#9972 a 1024-row mini-batch meant the check simply didn't run until 1024 values had been written, so the dedup survived. That was an accident of `write_batch_size`, not a designed property — the same column at 2000 rows already lost the prefix at the 1024-value boundary. This matters for choosing a fix: **making the byte budget encoding-aware (suggestion 2 in the issue) does not fix the reported bug.** However precise the budget, the first value alone still exceeds the limit and still triggers the flush. ## The fix Parquet requires at least one value per data page, so a value larger than the limit cannot be split out — the limit is unsatisfiable for it. Counting those bytes against the limit is what forces the pathological one-value-per-page cut. Record that first value's encoded size in `PageMetrics::page_size_floor` and apply the limit to what follows it, i.e. the bytes that *can* still go on another page. The exemption is gated on a new `ColumnValueEncoder::compresses_against_previous_value` (default `false`, `true` only for `DELTA_BYTE_ARRAY` in both the generic and arrow encoders). `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` cost the same wherever a value lands, so there is nothing to preserve by keeping values together and they keep their existing tighter one-value page bound. All three regression tests from apache#9972 pass unmodified. ## Why not "don't split when the split cannot help" Suggestion 1 in the issue restores the dedup, but by removing the bound that apache#9972 added, for exactly the workload it was added for. Measured with `Some(1) => chunk_size` in `byte_budget_chunker.rs`, 2048 rows × 128 KiB distinct values against a 64 KiB page limit — the same regime as a 10 MB value against the 1 MiB default, scaled to fit in RAM: | | pages | max page | |---|---|---| | 59.1.0 | 2048 | 128 KiB | | suggestion 1 | 2 | **128 MiB** | | this PR | 1024 | 256 KiB | Page size under suggestion 1 is `write_batch_size × value_size`. At 1024 × 10 MB that is a 10 GB page, which is the failure apache#9972 fixed. ## Results The reporter's table, reproduced verbatim (10 identical 8 MiB values, raw input 80 MiB): | `data_page_size_limit` | 58.4.0 | 59.1.0 | this PR | | --- | --- | --- | --- | | default (1 MiB) | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 4 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 8 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 16 MiB | 8.00 MiB | 8.00 MiB | **8.00 MiB** | Values that merely share a long prefix behave the same. Values sharing *no* prefix are unaffected in file size and stay bounded at up to two values per page — the exempt one plus the one that trips the budget. ## Tests - `test_column_writer_delta_byte_array_dedups_large_shared_prefix_values` — 16 identical 64 KiB values, 16 KiB page limit. Fails on `main` with 1 MiB across 16 pages (byte for byte what `PLAIN` produces); passes here at ~one value's worth. - `test_column_writer_delta_byte_array_bounds_pages_without_shared_prefix` — the same column with values differing from byte 0, asserting pages stay bounded by two values. Guards against fixing this by dropping the bound. - `test_large_string_delta_byte_array_shared_prefix` — the `ArrowWriter` path from the report, as an exact page-layout assertion. ## Notes One known limitation, pinned by `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup`: the exemption triggers when a page opens with a mini-batch holding exactly one value. That is guaranteed for chunks without nulls (the byte-budget chunker gives an over-limit value its own mini-batch), but a null in a chunk makes the chunker convert values to levels by ratio and round up, so pages can open with a two-value mini-batch, miss the exemption, and store their first value in full. Dedup on such columns is partial rather than absent, and never worse than `main`, which stores every value in full. The clean fix is for the granular path to cut windows after an exact value count instead of ratio-scaling; that is independent of this change and tracked in apache#10538. The pinning test documents the layout to expect once it lands. A follow-up worth considering separately: the byte budget in `count_within_budget_*` still measures raw payload length, so `DELTA_BYTE_ARRAY` columns sub-batch more eagerly than the encoded size warrants. That is a throughput question rather than a correctness one, and it is not what caused this regression. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <[email protected]>
…ounts (#10554) - closes #10538 > [!IMPORTANT] > **Stacked on #10505 and #10745 — do not merge first.** The commits below the top one belong to those PRs. > Review only this PR's own commit: [`cff2ca07fe...bd66b9e`](pydantic/arrow-rs@cff2ca0...bd66b9e). > Once #10505 and #10745 merge I'll rebase and this PR's diff becomes clean on its own. ## The problem `byte_budget_sub_batch_size` asks the encoder how many *values* fit in a page byte budget, then converts that to a *level* count using the chunk-wide level:value ratio, rounded up: ```rust (values_per_subbatch * chunk_size).div_ceil(vals_in_chunk).max(1) ``` For a chunk with no nulls this is exact. With one null in 17 levels it gives `ceil(17/16) == 2`, and `write_granular_chunk` slices the chunk into uniform two-level windows — most of which carry **two** values, i.e. twice what the budget allowed. The mechanism predates #10505; it dates to #9972. Where the encoding compresses a value against its predecessor, that round-up costs whole values of output. 128 values of 2 MiB at one null in 16: | | file size | | --- | --- | | ratio-scaled windows | 16.78 MB | | value-exact windows | **2.10 MB** | At 8 MiB values it is 64 MiB against 8 MiB, and the acceptance case in #10538 — 16 identical 64 KiB values with one null — goes from five pages storing ~5 values in full to one page storing ~1. ## The fix Have the chunker return the value count it already computed, and let `write_granular_chunk` end a window by walking definition levels until it has covered that many values. No ratio, no rounding. Then apply it only where it changes the bytes written, because it is not free — value-exact windows roughly double the mini-batch count on a nullable column. Two conditions, both required: **The budget must be the data page budget.** That one is a constant `data_page_size_limit`, so a one-value budget means the value itself overflows a page. The dictionary page budget is the limit *minus what the dictionary already holds*, so it shrinks toward zero as the dictionary fills and reaches a one-value budget on perfectly ordinary values; cutting exactly there measured +13.0% on `string/default` and +8.3% on `string/parquet_2`. **The encoding must compress against the previous value.** `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` store a value identically wherever it lands, so value-exact windows leave their output byte for byte the same while doubling the page count — measured +27.6% on a nullable column for no reduction in output at all. The `compresses_against_previous_value` flag #10505 added already marks exactly the right set. ## What the other paths give up A ratio-scaled window spans `ceil(values × levels / values_in_chunk)` levels. Where one value already fills the budget that covers **at most two values**, whatever the null density, and exactly one wherever the ratio is a whole number. Measured against a 1 MiB limit: | values | nulls | encoding | max page, ratio | max page, value-exact | floor | | --- | --- | --- | --- | --- | --- | | 2 MiB | 1-in-16 | `PLAIN` | 4.00× | 2.00× | 2.00× | | 2 MiB | 1-in-4 | `PLAIN` | 4.00× | 2.00× | 2.00× | | 2 MiB | 1-in-2 | `PLAIN` | 2.00× | 2.00× | 2.00× | | 8 MiB | 1-in-16 | `PLAIN` | 16.00× | 8.00× | 8.00× | The floor is what a page must hold: one value. So the concession is a factor of two above an unavoidable minimum, it does not vary with null density, and — the property #9972 exists for — it does not scale with `write_batch_size`. Before #9972 a page took a whole mini-batch: 1024 × 2 MiB, roughly 2000× the limit. ## Measurements Base is #10505's head (measured at `fd806be5d3`; both branches have since been rebased onto `main`, with the trees verified identical across the rebase), so these isolate this PR. Local, run base → branch → base on an idle machine, with the two base passes as a per-benchmark noise floor. Benchmarks are the ones added in #10561. | benchmark | before the encoding gate | after | noise | | --- | --- | --- | --- | | `..._nullable/plain` | +27.6% | **−0.8%** | 0.4% | | `..._nullable_trailing/delta_byte_array` | −27.8% | **−27.5%** | 0.8% | | `..._nullable/delta_byte_array` | +7.6% | +7.4% | 0.0% | | `..._nullable_dense/delta_byte_array` | −0.2% | +0.6% | 1.0% | | `large_string_distinct_nullable/delta_byte_array` | +3.1% | +11.3% | 2.0% | | `medium_string_shared_prefix_nullable/delta_byte_array` | +1.3% | +1.7% | 1.2% | Two costs remain, both on `DELTA_BYTE_ARRAY` where the byte win does not materialise: - **+7.4%** where output was already close to deduplicated (16.78 MB → 2.10 MB is still a 8× reduction, so this one pays for itself). - **+11.3%** where the values share no prefix at all, and the file is 251.670105 MB against 251.670637 MB — no reduction. The writer cannot know in advance whether values will share prefixes, so this is the premium for the 8× win when they do. Verified byte-identical output — same length, same hash — between base and this PR for dictionary-encoded nullable columns (four shapes) and for repeated columns (both encodings), confirming those paths are untouched rather than merely unchanged in aggregate. ## Scope Repeated columns are unchanged: records cannot span pages, so a record holding several over-limit values still exceeds the budget. That is inherent to the format. ## Tests - `test_column_writer_delta_byte_array_nullable_shared_prefix_dedup` — re-pinned from `[2, 2, 2, 2, 9]` to `[17]` and renamed, the layout #10505 left a marker for. - `test_column_writer_caps_page_size_with_sparse_nulls` — pins two values per page under `PLAIN`, so it fails both if the encoding gate is dropped (pages would hold one) and if the bound is lost (they would hold many). Full `parquet` suite green (1312 lib + integration), `fmt` and `clippy -D warnings` clean. ## Note on #10505 Its `bool_to_int_with_if` trips `cargo clippy -- -D warnings`, which CI runs — worth fixing on that branch too. Corrected here as part of editing that test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <[email protected]>
…ache#10745) - Follow-up to apache#10505 / apache#10554 (independent of both; apache#10554 is now stacked on top of this) ## What `compute_min_max` in `arrow_writer/byte_array.rs` copies both the minimum and the maximum of every mini-batch into fresh `ByteArray`s (`to_vec()`) before `encode` has checked whether either one beats the running page min/max. `write_gather` runs once per mini-batch, and a byte-budgeted mini-batch of large values can hold a single value — so every large value was being allocated and copied twice more, on top of the copies the encoder itself needs. This returns the borrowed extremes and copies only when the running value actually changes. Statistics are unchanged; the comparison is the same byte-lexicographic order `ByteArray` uses. It only ever removes copies, so it cannot cost more anywhere. ## Why now Found while profiling apache#10554 (value-exact mini-batch windows), which showed **+12…15%** on `large_string_distinct_nullable/delta_byte_array` across three runner runs against both `main` and apache#10505. `samply` put the whole shift into `memmove` under `ByteArrayEncoder::write_gather`; the encoding work per value is identical, so the cost had to be per-mini-batch — and apache#10554 roughly doubles the mini-batch count on nullable columns. That was this copy. ## Measurements Runner (`c4a-highmem-16`), three runs each way with identical-code controls; full tables and links in the [results comment](apache#10745 (comment)). Isolated (stacked on apache#10554, vs apache#10554 head): | benchmark | mean of 3 | control | |---|---|---| | `large_string_shared_prefix_nullable/delta_byte_array` | **−24.4%** | +0.8 | | `large_string_shared_prefix_nullable_trailing/delta_byte_array` | **−23.2%** | −0.2 | | `large_string_shared_prefix_nullable_dense/delta_byte_array` | **−22.0%** | +0.7 | | `large_string_shared_prefix/delta_byte_array` (non-null) | **−21.9%** | −0.7 | | `medium_string_shared_prefix_nullable/delta_byte_array` | −7.2% | +4.9 | | `large_string_distinct_nullable/delta_byte_array` | −5.4% | −0.8 | | `large_string_distinct/delta_byte_array` | −4.0% | −0.2 | Effect on apache#10554's regression: `large_string_distinct_nullable/delta_byte_array` vs apache#10505 goes from **+14.7% to +5.4%**, and its `_nullable` shape from +18.3% to −13.6%. Alone, vs `main`: the over-limit `DELTA_BYTE_ARRAY` benches are flat — there every over-limit value already opens its own page (the bug apache#10505 fixes), so `flush_data_page` takes the running min/max on every mini-batch and both copies happen regardless. `large_string_non_null/*` (1024 × 256 KiB, default properties) is **−7…−9%** in all three full runs with a flat control, so it pays today wherever a page holds more than one mini-batch of large values. Nothing else moves outside what the main-vs-main control moves on identical code. ## Tests No behaviour change; full `parquet` suite green, `fmt` and `clippy -D warnings` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
…page size limit (apache#10505) - closes apache#10489 - closes apache#10504 ## The cause is the page flush, not the mini-batch splitting The issue attributes the regression to apache#9972's byte-budget sub-batching. It's actually the page flush; the sub-batching only exposes it. `should_add_data_page` fires when `estimated_data_page_size() >= data_page_size_limit`. For `DELTA_BYTE_ARRAY` that estimate is the real encoded size, and the first value on a page is stored in full — so a single 8 MiB value against a 1 MiB limit puts the page over the limit by itself and triggers a flush. Flushing clears the encoder's `previous`, so the next value gets `prefix_length = 0`, and so on. The encoding degenerates to exactly `PLAIN`. Before apache#9972 a 1024-row mini-batch meant the check simply didn't run until 1024 values had been written, so the dedup survived. That was an accident of `write_batch_size`, not a designed property — the same column at 2000 rows already lost the prefix at the 1024-value boundary. This matters for choosing a fix: **making the byte budget encoding-aware (suggestion 2 in the issue) does not fix the reported bug.** However precise the budget, the first value alone still exceeds the limit and still triggers the flush. ## The fix Parquet requires at least one value per data page, so a value larger than the limit cannot be split out — the limit is unsatisfiable for it. Counting those bytes against the limit is what forces the pathological one-value-per-page cut. Record that first value's encoded size in `PageMetrics::page_size_floor` and apply the limit to what follows it, i.e. the bytes that *can* still go on another page. The exemption is gated on a new `ColumnValueEncoder::compresses_against_previous_value` (default `false`, `true` only for `DELTA_BYTE_ARRAY` in both the generic and arrow encoders). `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` cost the same wherever a value lands, so there is nothing to preserve by keeping values together and they keep their existing tighter one-value page bound. All three regression tests from apache#9972 pass unmodified. ## Why not "don't split when the split cannot help" Suggestion 1 in the issue restores the dedup, but by removing the bound that apache#9972 added, for exactly the workload it was added for. Measured with `Some(1) => chunk_size` in `byte_budget_chunker.rs`, 2048 rows × 128 KiB distinct values against a 64 KiB page limit — the same regime as a 10 MB value against the 1 MiB default, scaled to fit in RAM: | | pages | max page | |---|---|---| | 59.1.0 | 2048 | 128 KiB | | suggestion 1 | 2 | **128 MiB** | | this PR | 1024 | 256 KiB | Page size under suggestion 1 is `write_batch_size × value_size`. At 1024 × 10 MB that is a 10 GB page, which is the failure apache#9972 fixed. ## Results The reporter's table, reproduced verbatim (10 identical 8 MiB values, raw input 80 MiB): | `data_page_size_limit` | 58.4.0 | 59.1.0 | this PR | | --- | --- | --- | --- | | default (1 MiB) | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 4 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 8 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 16 MiB | 8.00 MiB | 8.00 MiB | **8.00 MiB** | Values that merely share a long prefix behave the same. Values sharing *no* prefix are unaffected in file size and stay bounded at up to two values per page — the exempt one plus the one that trips the budget. ## Tests - `test_column_writer_delta_byte_array_dedups_large_shared_prefix_values` — 16 identical 64 KiB values, 16 KiB page limit. Fails on `main` with 1 MiB across 16 pages (byte for byte what `PLAIN` produces); passes here at ~one value's worth. - `test_column_writer_delta_byte_array_bounds_pages_without_shared_prefix` — the same column with values differing from byte 0, asserting pages stay bounded by two values. Guards against fixing this by dropping the bound. - `test_large_string_delta_byte_array_shared_prefix` — the `ArrowWriter` path from the report, as an exact page-layout assertion. ## Notes One known limitation, pinned by `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup`: the exemption triggers when a page opens with a mini-batch holding exactly one value. That is guaranteed for chunks without nulls (the byte-budget chunker gives an over-limit value its own mini-batch), but a null in a chunk makes the chunker convert values to levels by ratio and round up, so pages can open with a two-value mini-batch, miss the exemption, and store their first value in full. Dedup on such columns is partial rather than absent, and never worse than `main`, which stores every value in full. The clean fix is for the granular path to cut windows after an exact value count instead of ratio-scaling; that is independent of this change and tracked in apache#10538. The pinning test documents the layout to expect once it lands. A follow-up worth considering separately: the byte budget in `count_within_budget_*` still measures raw payload length, so `DELTA_BYTE_ARRAY` columns sub-batch more eagerly than the encoded size warrants. That is a throughput question rather than a correctness one, and it is not what caused this regression. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <[email protected]>
…ounts (apache#10554) - closes apache#10538 > [!IMPORTANT] > **Stacked on apache#10505 and apache#10745 — do not merge first.** The commits below the top one belong to those PRs. > Review only this PR's own commit: [`cff2ca07fe...bd66b9e`](pydantic/arrow-rs@cff2ca0...bd66b9e). > Once apache#10505 and apache#10745 merge I'll rebase and this PR's diff becomes clean on its own. ## The problem `byte_budget_sub_batch_size` asks the encoder how many *values* fit in a page byte budget, then converts that to a *level* count using the chunk-wide level:value ratio, rounded up: ```rust (values_per_subbatch * chunk_size).div_ceil(vals_in_chunk).max(1) ``` For a chunk with no nulls this is exact. With one null in 17 levels it gives `ceil(17/16) == 2`, and `write_granular_chunk` slices the chunk into uniform two-level windows — most of which carry **two** values, i.e. twice what the budget allowed. The mechanism predates apache#10505; it dates to apache#9972. Where the encoding compresses a value against its predecessor, that round-up costs whole values of output. 128 values of 2 MiB at one null in 16: | | file size | | --- | --- | | ratio-scaled windows | 16.78 MB | | value-exact windows | **2.10 MB** | At 8 MiB values it is 64 MiB against 8 MiB, and the acceptance case in apache#10538 — 16 identical 64 KiB values with one null — goes from five pages storing ~5 values in full to one page storing ~1. ## The fix Have the chunker return the value count it already computed, and let `write_granular_chunk` end a window by walking definition levels until it has covered that many values. No ratio, no rounding. Then apply it only where it changes the bytes written, because it is not free — value-exact windows roughly double the mini-batch count on a nullable column. Two conditions, both required: **The budget must be the data page budget.** That one is a constant `data_page_size_limit`, so a one-value budget means the value itself overflows a page. The dictionary page budget is the limit *minus what the dictionary already holds*, so it shrinks toward zero as the dictionary fills and reaches a one-value budget on perfectly ordinary values; cutting exactly there measured +13.0% on `string/default` and +8.3% on `string/parquet_2`. **The encoding must compress against the previous value.** `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` store a value identically wherever it lands, so value-exact windows leave their output byte for byte the same while doubling the page count — measured +27.6% on a nullable column for no reduction in output at all. The `compresses_against_previous_value` flag apache#10505 added already marks exactly the right set. ## What the other paths give up A ratio-scaled window spans `ceil(values × levels / values_in_chunk)` levels. Where one value already fills the budget that covers **at most two values**, whatever the null density, and exactly one wherever the ratio is a whole number. Measured against a 1 MiB limit: | values | nulls | encoding | max page, ratio | max page, value-exact | floor | | --- | --- | --- | --- | --- | --- | | 2 MiB | 1-in-16 | `PLAIN` | 4.00× | 2.00× | 2.00× | | 2 MiB | 1-in-4 | `PLAIN` | 4.00× | 2.00× | 2.00× | | 2 MiB | 1-in-2 | `PLAIN` | 2.00× | 2.00× | 2.00× | | 8 MiB | 1-in-16 | `PLAIN` | 16.00× | 8.00× | 8.00× | The floor is what a page must hold: one value. So the concession is a factor of two above an unavoidable minimum, it does not vary with null density, and — the property apache#9972 exists for — it does not scale with `write_batch_size`. Before apache#9972 a page took a whole mini-batch: 1024 × 2 MiB, roughly 2000× the limit. ## Measurements Base is apache#10505's head (measured at `fd806be5d3`; both branches have since been rebased onto `main`, with the trees verified identical across the rebase), so these isolate this PR. Local, run base → branch → base on an idle machine, with the two base passes as a per-benchmark noise floor. Benchmarks are the ones added in apache#10561. | benchmark | before the encoding gate | after | noise | | --- | --- | --- | --- | | `..._nullable/plain` | +27.6% | **−0.8%** | 0.4% | | `..._nullable_trailing/delta_byte_array` | −27.8% | **−27.5%** | 0.8% | | `..._nullable/delta_byte_array` | +7.6% | +7.4% | 0.0% | | `..._nullable_dense/delta_byte_array` | −0.2% | +0.6% | 1.0% | | `large_string_distinct_nullable/delta_byte_array` | +3.1% | +11.3% | 2.0% | | `medium_string_shared_prefix_nullable/delta_byte_array` | +1.3% | +1.7% | 1.2% | Two costs remain, both on `DELTA_BYTE_ARRAY` where the byte win does not materialise: - **+7.4%** where output was already close to deduplicated (16.78 MB → 2.10 MB is still a 8× reduction, so this one pays for itself). - **+11.3%** where the values share no prefix at all, and the file is 251.670105 MB against 251.670637 MB — no reduction. The writer cannot know in advance whether values will share prefixes, so this is the premium for the 8× win when they do. Verified byte-identical output — same length, same hash — between base and this PR for dictionary-encoded nullable columns (four shapes) and for repeated columns (both encodings), confirming those paths are untouched rather than merely unchanged in aggregate. ## Scope Repeated columns are unchanged: records cannot span pages, so a record holding several over-limit values still exceeds the budget. That is inherent to the format. ## Tests - `test_column_writer_delta_byte_array_nullable_shared_prefix_dedup` — re-pinned from `[2, 2, 2, 2, 9]` to `[17]` and renamed, the layout apache#10505 left a marker for. - `test_column_writer_caps_page_size_with_sparse_nulls` — pins two values per page under `PLAIN`, so it fails both if the encoding gate is dropped (pages would hold one) and if the bound is lost (they would hold many). Full `parquet` suite green (1312 lib + integration), `fmt` and `clippy -D warnings` clean. ## Note on apache#10505 Its `bool_to_int_with_if` trips `cargo clippy -- -D warnings`, which CI runs — worth fixing on that branch too. Corrected here as part of editing that test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <[email protected]>
…ache#10745) - Follow-up to apache#10505 / apache#10554 (independent of both; apache#10554 is now stacked on top of this) ## What `compute_min_max` in `arrow_writer/byte_array.rs` copies both the minimum and the maximum of every mini-batch into fresh `ByteArray`s (`to_vec()`) before `encode` has checked whether either one beats the running page min/max. `write_gather` runs once per mini-batch, and a byte-budgeted mini-batch of large values can hold a single value — so every large value was being allocated and copied twice more, on top of the copies the encoder itself needs. This returns the borrowed extremes and copies only when the running value actually changes. Statistics are unchanged; the comparison is the same byte-lexicographic order `ByteArray` uses. It only ever removes copies, so it cannot cost more anywhere. ## Why now Found while profiling apache#10554 (value-exact mini-batch windows), which showed **+12…15%** on `large_string_distinct_nullable/delta_byte_array` across three runner runs against both `main` and apache#10505. `samply` put the whole shift into `memmove` under `ByteArrayEncoder::write_gather`; the encoding work per value is identical, so the cost had to be per-mini-batch — and apache#10554 roughly doubles the mini-batch count on nullable columns. That was this copy. ## Measurements Runner (`c4a-highmem-16`), three runs each way with identical-code controls; full tables and links in the [results comment](apache#10745 (comment)). Isolated (stacked on apache#10554, vs apache#10554 head): | benchmark | mean of 3 | control | |---|---|---| | `large_string_shared_prefix_nullable/delta_byte_array` | **−24.4%** | +0.8 | | `large_string_shared_prefix_nullable_trailing/delta_byte_array` | **−23.2%** | −0.2 | | `large_string_shared_prefix_nullable_dense/delta_byte_array` | **−22.0%** | +0.7 | | `large_string_shared_prefix/delta_byte_array` (non-null) | **−21.9%** | −0.7 | | `medium_string_shared_prefix_nullable/delta_byte_array` | −7.2% | +4.9 | | `large_string_distinct_nullable/delta_byte_array` | −5.4% | −0.8 | | `large_string_distinct/delta_byte_array` | −4.0% | −0.2 | Effect on apache#10554's regression: `large_string_distinct_nullable/delta_byte_array` vs apache#10505 goes from **+14.7% to +5.4%**, and its `_nullable` shape from +18.3% to −13.6%. Alone, vs `main`: the over-limit `DELTA_BYTE_ARRAY` benches are flat — there every over-limit value already opens its own page (the bug apache#10505 fixes), so `flush_data_page` takes the running min/max on every mini-batch and both copies happen regardless. `large_string_non_null/*` (1024 × 256 KiB, default properties) is **−7…−9%** in all three full runs with a flat control, so it pays today wherever a page holds more than one mini-batch of large values. Nothing else moves outside what the main-vs-main control moves on identical code. ## Tests No behaviour change; full `parquet` suite green, `fmt` and `clippy -D warnings` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
…page size limit (apache#10505) - closes apache#10489 - closes apache#10504 ## The cause is the page flush, not the mini-batch splitting The issue attributes the regression to apache#9972's byte-budget sub-batching. It's actually the page flush; the sub-batching only exposes it. `should_add_data_page` fires when `estimated_data_page_size() >= data_page_size_limit`. For `DELTA_BYTE_ARRAY` that estimate is the real encoded size, and the first value on a page is stored in full — so a single 8 MiB value against a 1 MiB limit puts the page over the limit by itself and triggers a flush. Flushing clears the encoder's `previous`, so the next value gets `prefix_length = 0`, and so on. The encoding degenerates to exactly `PLAIN`. Before apache#9972 a 1024-row mini-batch meant the check simply didn't run until 1024 values had been written, so the dedup survived. That was an accident of `write_batch_size`, not a designed property — the same column at 2000 rows already lost the prefix at the 1024-value boundary. This matters for choosing a fix: **making the byte budget encoding-aware (suggestion 2 in the issue) does not fix the reported bug.** However precise the budget, the first value alone still exceeds the limit and still triggers the flush. ## The fix Parquet requires at least one value per data page, so a value larger than the limit cannot be split out — the limit is unsatisfiable for it. Counting those bytes against the limit is what forces the pathological one-value-per-page cut. Record that first value's encoded size in `PageMetrics::page_size_floor` and apply the limit to what follows it, i.e. the bytes that *can* still go on another page. The exemption is gated on a new `ColumnValueEncoder::compresses_against_previous_value` (default `false`, `true` only for `DELTA_BYTE_ARRAY` in both the generic and arrow encoders). `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` cost the same wherever a value lands, so there is nothing to preserve by keeping values together and they keep their existing tighter one-value page bound. All three regression tests from apache#9972 pass unmodified. ## Why not "don't split when the split cannot help" Suggestion 1 in the issue restores the dedup, but by removing the bound that apache#9972 added, for exactly the workload it was added for. Measured with `Some(1) => chunk_size` in `byte_budget_chunker.rs`, 2048 rows × 128 KiB distinct values against a 64 KiB page limit — the same regime as a 10 MB value against the 1 MiB default, scaled to fit in RAM: | | pages | max page | |---|---|---| | 59.1.0 | 2048 | 128 KiB | | suggestion 1 | 2 | **128 MiB** | | this PR | 1024 | 256 KiB | Page size under suggestion 1 is `write_batch_size × value_size`. At 1024 × 10 MB that is a 10 GB page, which is the failure apache#9972 fixed. ## Results The reporter's table, reproduced verbatim (10 identical 8 MiB values, raw input 80 MiB): | `data_page_size_limit` | 58.4.0 | 59.1.0 | this PR | | --- | --- | --- | --- | | default (1 MiB) | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 4 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 8 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 16 MiB | 8.00 MiB | 8.00 MiB | **8.00 MiB** | Values that merely share a long prefix behave the same. Values sharing *no* prefix are unaffected in file size and stay bounded at up to two values per page — the exempt one plus the one that trips the budget. ## Tests - `test_column_writer_delta_byte_array_dedups_large_shared_prefix_values` — 16 identical 64 KiB values, 16 KiB page limit. Fails on `main` with 1 MiB across 16 pages (byte for byte what `PLAIN` produces); passes here at ~one value's worth. - `test_column_writer_delta_byte_array_bounds_pages_without_shared_prefix` — the same column with values differing from byte 0, asserting pages stay bounded by two values. Guards against fixing this by dropping the bound. - `test_large_string_delta_byte_array_shared_prefix` — the `ArrowWriter` path from the report, as an exact page-layout assertion. ## Notes One known limitation, pinned by `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup`: the exemption triggers when a page opens with a mini-batch holding exactly one value. That is guaranteed for chunks without nulls (the byte-budget chunker gives an over-limit value its own mini-batch), but a null in a chunk makes the chunker convert values to levels by ratio and round up, so pages can open with a two-value mini-batch, miss the exemption, and store their first value in full. Dedup on such columns is partial rather than absent, and never worse than `main`, which stores every value in full. The clean fix is for the granular path to cut windows after an exact value count instead of ratio-scaling; that is independent of this change and tracked in apache#10538. The pinning test documents the layout to expect once it lands. A follow-up worth considering separately: the byte budget in `count_within_budget_*` still measures raw payload length, so `DELTA_BYTE_ARRAY` columns sub-batch more eagerly than the encoded size warrants. That is a throughput question rather than a correctness one, and it is not what caused this regression. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <[email protected]>
…ounts (apache#10554) - closes apache#10538 > [!IMPORTANT] > **Stacked on apache#10505 and apache#10745 — do not merge first.** The commits below the top one belong to those PRs. > Review only this PR's own commit: [`cff2ca07fe...bd66b9e`](pydantic/arrow-rs@cff2ca0...bd66b9e). > Once apache#10505 and apache#10745 merge I'll rebase and this PR's diff becomes clean on its own. ## The problem `byte_budget_sub_batch_size` asks the encoder how many *values* fit in a page byte budget, then converts that to a *level* count using the chunk-wide level:value ratio, rounded up: ```rust (values_per_subbatch * chunk_size).div_ceil(vals_in_chunk).max(1) ``` For a chunk with no nulls this is exact. With one null in 17 levels it gives `ceil(17/16) == 2`, and `write_granular_chunk` slices the chunk into uniform two-level windows — most of which carry **two** values, i.e. twice what the budget allowed. The mechanism predates apache#10505; it dates to apache#9972. Where the encoding compresses a value against its predecessor, that round-up costs whole values of output. 128 values of 2 MiB at one null in 16: | | file size | | --- | --- | | ratio-scaled windows | 16.78 MB | | value-exact windows | **2.10 MB** | At 8 MiB values it is 64 MiB against 8 MiB, and the acceptance case in apache#10538 — 16 identical 64 KiB values with one null — goes from five pages storing ~5 values in full to one page storing ~1. ## The fix Have the chunker return the value count it already computed, and let `write_granular_chunk` end a window by walking definition levels until it has covered that many values. No ratio, no rounding. Then apply it only where it changes the bytes written, because it is not free — value-exact windows roughly double the mini-batch count on a nullable column. Two conditions, both required: **The budget must be the data page budget.** That one is a constant `data_page_size_limit`, so a one-value budget means the value itself overflows a page. The dictionary page budget is the limit *minus what the dictionary already holds*, so it shrinks toward zero as the dictionary fills and reaches a one-value budget on perfectly ordinary values; cutting exactly there measured +13.0% on `string/default` and +8.3% on `string/parquet_2`. **The encoding must compress against the previous value.** `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` store a value identically wherever it lands, so value-exact windows leave their output byte for byte the same while doubling the page count — measured +27.6% on a nullable column for no reduction in output at all. The `compresses_against_previous_value` flag apache#10505 added already marks exactly the right set. ## What the other paths give up A ratio-scaled window spans `ceil(values × levels / values_in_chunk)` levels. Where one value already fills the budget that covers **at most two values**, whatever the null density, and exactly one wherever the ratio is a whole number. Measured against a 1 MiB limit: | values | nulls | encoding | max page, ratio | max page, value-exact | floor | | --- | --- | --- | --- | --- | --- | | 2 MiB | 1-in-16 | `PLAIN` | 4.00× | 2.00× | 2.00× | | 2 MiB | 1-in-4 | `PLAIN` | 4.00× | 2.00× | 2.00× | | 2 MiB | 1-in-2 | `PLAIN` | 2.00× | 2.00× | 2.00× | | 8 MiB | 1-in-16 | `PLAIN` | 16.00× | 8.00× | 8.00× | The floor is what a page must hold: one value. So the concession is a factor of two above an unavoidable minimum, it does not vary with null density, and — the property apache#9972 exists for — it does not scale with `write_batch_size`. Before apache#9972 a page took a whole mini-batch: 1024 × 2 MiB, roughly 2000× the limit. ## Measurements Base is apache#10505's head (measured at `fd806be5d3`; both branches have since been rebased onto `main`, with the trees verified identical across the rebase), so these isolate this PR. Local, run base → branch → base on an idle machine, with the two base passes as a per-benchmark noise floor. Benchmarks are the ones added in apache#10561. | benchmark | before the encoding gate | after | noise | | --- | --- | --- | --- | | `..._nullable/plain` | +27.6% | **−0.8%** | 0.4% | | `..._nullable_trailing/delta_byte_array` | −27.8% | **−27.5%** | 0.8% | | `..._nullable/delta_byte_array` | +7.6% | +7.4% | 0.0% | | `..._nullable_dense/delta_byte_array` | −0.2% | +0.6% | 1.0% | | `large_string_distinct_nullable/delta_byte_array` | +3.1% | +11.3% | 2.0% | | `medium_string_shared_prefix_nullable/delta_byte_array` | +1.3% | +1.7% | 1.2% | Two costs remain, both on `DELTA_BYTE_ARRAY` where the byte win does not materialise: - **+7.4%** where output was already close to deduplicated (16.78 MB → 2.10 MB is still a 8× reduction, so this one pays for itself). - **+11.3%** where the values share no prefix at all, and the file is 251.670105 MB against 251.670637 MB — no reduction. The writer cannot know in advance whether values will share prefixes, so this is the premium for the 8× win when they do. Verified byte-identical output — same length, same hash — between base and this PR for dictionary-encoded nullable columns (four shapes) and for repeated columns (both encodings), confirming those paths are untouched rather than merely unchanged in aggregate. ## Scope Repeated columns are unchanged: records cannot span pages, so a record holding several over-limit values still exceeds the budget. That is inherent to the format. ## Tests - `test_column_writer_delta_byte_array_nullable_shared_prefix_dedup` — re-pinned from `[2, 2, 2, 2, 9]` to `[17]` and renamed, the layout apache#10505 left a marker for. - `test_column_writer_caps_page_size_with_sparse_nulls` — pins two values per page under `PLAIN`, so it fails both if the encoding gate is dropped (pages would hold one) and if the bound is lost (they would hold many). Full `parquet` suite green (1312 lib + integration), `fmt` and `clippy -D warnings` clean. ## Note on apache#10505 Its `bool_to_int_with_if` trips `cargo clippy -- -D warnings`, which CI runs — worth fixing on that branch too. Corrected here as part of editing that test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <[email protected]>
…ache#10745) - Follow-up to apache#10505 / apache#10554 (independent of both; apache#10554 is now stacked on top of this) ## What `compute_min_max` in `arrow_writer/byte_array.rs` copies both the minimum and the maximum of every mini-batch into fresh `ByteArray`s (`to_vec()`) before `encode` has checked whether either one beats the running page min/max. `write_gather` runs once per mini-batch, and a byte-budgeted mini-batch of large values can hold a single value — so every large value was being allocated and copied twice more, on top of the copies the encoder itself needs. This returns the borrowed extremes and copies only when the running value actually changes. Statistics are unchanged; the comparison is the same byte-lexicographic order `ByteArray` uses. It only ever removes copies, so it cannot cost more anywhere. ## Why now Found while profiling apache#10554 (value-exact mini-batch windows), which showed **+12…15%** on `large_string_distinct_nullable/delta_byte_array` across three runner runs against both `main` and apache#10505. `samply` put the whole shift into `memmove` under `ByteArrayEncoder::write_gather`; the encoding work per value is identical, so the cost had to be per-mini-batch — and apache#10554 roughly doubles the mini-batch count on nullable columns. That was this copy. ## Measurements Runner (`c4a-highmem-16`), three runs each way with identical-code controls; full tables and links in the [results comment](apache#10745 (comment)). Isolated (stacked on apache#10554, vs apache#10554 head): | benchmark | mean of 3 | control | |---|---|---| | `large_string_shared_prefix_nullable/delta_byte_array` | **−24.4%** | +0.8 | | `large_string_shared_prefix_nullable_trailing/delta_byte_array` | **−23.2%** | −0.2 | | `large_string_shared_prefix_nullable_dense/delta_byte_array` | **−22.0%** | +0.7 | | `large_string_shared_prefix/delta_byte_array` (non-null) | **−21.9%** | −0.7 | | `medium_string_shared_prefix_nullable/delta_byte_array` | −7.2% | +4.9 | | `large_string_distinct_nullable/delta_byte_array` | −5.4% | −0.8 | | `large_string_distinct/delta_byte_array` | −4.0% | −0.2 | Effect on apache#10554's regression: `large_string_distinct_nullable/delta_byte_array` vs apache#10505 goes from **+14.7% to +5.4%**, and its `_nullable` shape from +18.3% to −13.6%. Alone, vs `main`: the over-limit `DELTA_BYTE_ARRAY` benches are flat — there every over-limit value already opens its own page (the bug apache#10505 fixes), so `flush_data_page` takes the running min/max on every mini-batch and both copies happen regardless. `large_string_non_null/*` (1024 × 256 KiB, default properties) is **−7…−9%** in all three full runs with a flat control, so it pays today wherever a page holds more than one mini-batch of large values. Nothing else moves outside what the main-vs-main control moves on identical code. ## Tests No behaviour change; full `parquet` suite green, `fmt` and `clippy -D warnings` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
…page size limit (apache#10505) - closes apache#10489 - closes apache#10504 ## The cause is the page flush, not the mini-batch splitting The issue attributes the regression to apache#9972's byte-budget sub-batching. It's actually the page flush; the sub-batching only exposes it. `should_add_data_page` fires when `estimated_data_page_size() >= data_page_size_limit`. For `DELTA_BYTE_ARRAY` that estimate is the real encoded size, and the first value on a page is stored in full — so a single 8 MiB value against a 1 MiB limit puts the page over the limit by itself and triggers a flush. Flushing clears the encoder's `previous`, so the next value gets `prefix_length = 0`, and so on. The encoding degenerates to exactly `PLAIN`. Before apache#9972 a 1024-row mini-batch meant the check simply didn't run until 1024 values had been written, so the dedup survived. That was an accident of `write_batch_size`, not a designed property — the same column at 2000 rows already lost the prefix at the 1024-value boundary. This matters for choosing a fix: **making the byte budget encoding-aware (suggestion 2 in the issue) does not fix the reported bug.** However precise the budget, the first value alone still exceeds the limit and still triggers the flush. ## The fix Parquet requires at least one value per data page, so a value larger than the limit cannot be split out — the limit is unsatisfiable for it. Counting those bytes against the limit is what forces the pathological one-value-per-page cut. Record that first value's encoded size in `PageMetrics::page_size_floor` and apply the limit to what follows it, i.e. the bytes that *can* still go on another page. The exemption is gated on a new `ColumnValueEncoder::compresses_against_previous_value` (default `false`, `true` only for `DELTA_BYTE_ARRAY` in both the generic and arrow encoders). `PLAIN` and `DELTA_LENGTH_BYTE_ARRAY` cost the same wherever a value lands, so there is nothing to preserve by keeping values together and they keep their existing tighter one-value page bound. All three regression tests from apache#9972 pass unmodified. ## Why not "don't split when the split cannot help" Suggestion 1 in the issue restores the dedup, but by removing the bound that apache#9972 added, for exactly the workload it was added for. Measured with `Some(1) => chunk_size` in `byte_budget_chunker.rs`, 2048 rows × 128 KiB distinct values against a 64 KiB page limit — the same regime as a 10 MB value against the 1 MiB default, scaled to fit in RAM: | | pages | max page | |---|---|---| | 59.1.0 | 2048 | 128 KiB | | suggestion 1 | 2 | **128 MiB** | | this PR | 1024 | 256 KiB | Page size under suggestion 1 is `write_batch_size × value_size`. At 1024 × 10 MB that is a 10 GB page, which is the failure apache#9972 fixed. ## Results The reporter's table, reproduced verbatim (10 identical 8 MiB values, raw input 80 MiB): | `data_page_size_limit` | 58.4.0 | 59.1.0 | this PR | | --- | --- | --- | --- | | default (1 MiB) | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 4 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 8 MiB | 8.00 MiB | 80.00 MiB | **8.00 MiB** | | 16 MiB | 8.00 MiB | 8.00 MiB | **8.00 MiB** | Values that merely share a long prefix behave the same. Values sharing *no* prefix are unaffected in file size and stay bounded at up to two values per page — the exempt one plus the one that trips the budget. ## Tests - `test_column_writer_delta_byte_array_dedups_large_shared_prefix_values` — 16 identical 64 KiB values, 16 KiB page limit. Fails on `main` with 1 MiB across 16 pages (byte for byte what `PLAIN` produces); passes here at ~one value's worth. - `test_column_writer_delta_byte_array_bounds_pages_without_shared_prefix` — the same column with values differing from byte 0, asserting pages stay bounded by two values. Guards against fixing this by dropping the bound. - `test_large_string_delta_byte_array_shared_prefix` — the `ArrowWriter` path from the report, as an exact page-layout assertion. ## Notes One known limitation, pinned by `test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup`: the exemption triggers when a page opens with a mini-batch holding exactly one value. That is guaranteed for chunks without nulls (the byte-budget chunker gives an over-limit value its own mini-batch), but a null in a chunk makes the chunker convert values to levels by ratio and round up, so pages can open with a two-value mini-batch, miss the exemption, and store their first value in full. Dedup on such columns is partial rather than absent, and never worse than `main`, which stores every value in full. The clean fix is for the granular path to cut windows after an exact value count instead of ratio-scaling; that is independent of this change and tracked in apache#10538. The pinning test documents the layout to expect once it lands. A follow-up worth considering separately: the byte budget in `count_within_budget_*` still measures raw payload length, so `DELTA_BYTE_ARRAY` columns sub-batch more eagerly than the encoded size warrants. That is a throughput question rather than a correctness one, and it is not what caused this regression. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <[email protected]>
DELTA_BYTE_ARRAYstops deduplicating in parquet 59 for values larger than the page size limit #10489The cause is the page flush, not the mini-batch splitting
The issue attributes the regression to #9972's byte-budget sub-batching. It's actually the page flush; the sub-batching only exposes it.
should_add_data_pagefires whenestimated_data_page_size() >= data_page_size_limit. ForDELTA_BYTE_ARRAYthat estimate is the real encoded size, and the first value on a page is stored in full — so a single 8 MiB value against a 1 MiB limit puts the page over the limit by itself and triggers a flush. Flushing clears the encoder'sprevious, so the next value getsprefix_length = 0, and so on. The encoding degenerates to exactlyPLAIN.Before #9972 a 1024-row mini-batch meant the check simply didn't run until 1024 values had been written, so the dedup survived. That was an accident of
write_batch_size, not a designed property — the same column at 2000 rows already lost the prefix at the 1024-value boundary.This matters for choosing a fix: making the byte budget encoding-aware (suggestion 2 in the issue) does not fix the reported bug. However precise the budget, the first value alone still exceeds the limit and still triggers the flush.
The fix
Parquet requires at least one value per data page, so a value larger than the limit cannot be split out — the limit is unsatisfiable for it. Counting those bytes against the limit is what forces the pathological one-value-per-page cut.
Record that first value's encoded size in
PageMetrics::page_size_floorand apply the limit to what follows it, i.e. the bytes that can still go on another page.The exemption is gated on a new
ColumnValueEncoder::compresses_against_previous_value(defaultfalse,trueonly forDELTA_BYTE_ARRAYin both the generic and arrow encoders).PLAINandDELTA_LENGTH_BYTE_ARRAYcost the same wherever a value lands, so there is nothing to preserve by keeping values together and they keep their existing tighter one-value page bound. All three regression tests from #9972 pass unmodified.Why not "don't split when the split cannot help"
Suggestion 1 in the issue restores the dedup, but by removing the bound that #9972 added, for exactly the workload it was added for. Measured with
Some(1) => chunk_sizeinbyte_budget_chunker.rs, 2048 rows × 128 KiB distinct values against a 64 KiB page limit — the same regime as a 10 MB value against the 1 MiB default, scaled to fit in RAM:Page size under suggestion 1 is
write_batch_size × value_size. At 1024 × 10 MB that is a 10 GB page, which is the failure #9972 fixed.Results
The reporter's table, reproduced verbatim (10 identical 8 MiB values, raw input 80 MiB):
data_page_size_limitValues that merely share a long prefix behave the same. Values sharing no prefix are unaffected in file size and stay bounded at up to two values per page — the exempt one plus the one that trips the budget.
Tests
test_column_writer_delta_byte_array_dedups_large_shared_prefix_values— 16 identical 64 KiB values, 16 KiB page limit. Fails onmainwith 1 MiB across 16 pages (byte for byte whatPLAINproduces); passes here at ~one value's worth.test_column_writer_delta_byte_array_bounds_pages_without_shared_prefix— the same column with values differing from byte 0, asserting pages stay bounded by two values. Guards against fixing this by dropping the bound.test_large_string_delta_byte_array_shared_prefix— theArrowWriterpath from the report, as an exact page-layout assertion.Notes
One known limitation, pinned by
test_column_writer_delta_byte_array_nullable_shared_prefix_partial_dedup: the exemption triggers when a page opens with a mini-batch holding exactly one value. That is guaranteed for chunks without nulls (the byte-budget chunker gives an over-limit value its own mini-batch), but a null in a chunk makes the chunker convert values to levels by ratio and round up, so pages can open with a two-value mini-batch, miss the exemption, and store their first value in full. Dedup on such columns is partial rather than absent, and never worse thanmain, which stores every value in full. The clean fix is for the granular path to cut windows after an exact value count instead of ratio-scaling; that is independent of this change and tracked in #10538. The pinning test documents the layout to expect once it lands.A follow-up worth considering separately: the byte budget in
count_within_budget_*still measures raw payload length, soDELTA_BYTE_ARRAYcolumns sub-batch more eagerly than the encoded size warrants. That is a throughput question rather than a correctness one, and it is not what caused this regression.🤖 Generated with Claude Code