Repository navigation
perf(parquet): count fitting values before scanning def levels - #11997
Conversation
|
run benchmark arrow_writer |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 1 (1 workers). Comparing perf-byte-budget-precheck (3928536) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
3928536 to
f17e631
Compare
|
run benchmark arrow_writer |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 1 (1 workers). Comparing perf-byte-budget-precheck (f17e631) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
run benchmark arrow_writer |
|
🤖 Benchmark failed or incomplete (GKE) | trigger Target: arrow_writer Comparing perf-byte-budget-precheck (3928536) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 1
Errors / missing shardsPer-runner informationarrow_writer — shard 1/1Node: gk3-benchmark-cluster-nap-1fzug0kq-50073869-jzxw Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource UsageNo completed measurement resource samples. File an issue against this benchmark runner |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 4 (4 workers). Comparing perf-byte-budget-precheck (318bf4c) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark failed or incomplete (GKE) | trigger Target: arrow_writer Comparing perf-byte-budget-precheck (f17e631) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 1
Errors / missing shardsPer-runner informationarrow_writer — shard 1/1Node: gk3-benchmark-cluster-nap-6uf8krqf-51bf6dd9-z9n6 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource UsageNo completed measurement resource samples. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: arrow_writer Comparing perf-byte-budget-precheck (318bf4c) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Comparison results: View the complete native critcmp output. The comparison is published in an unlisted Gist because the original inline report exceeded GitHub's comment limit. Per-runner informationarrow_writer — shard 1/4Node: gk3-benchmark-cluster-nap-jeel64w1-66f44736-l628 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 2/4Node: gk3-benchmark-cluster-nap-1fzug0kq-50073869-h5nx Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 3/4Node: gk3-benchmark-cluster-nap-6uf8krqf-51bf6dd9-z9n6 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 4/4Node: gk3-benchmark-cluster-nap-1fzug0kq-c69560ca-b6ps Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
193e106 to
bf51fa4
Compare
|
run benchmark arrow_writer shards: 4 |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 4 (4 workers). Comparing perf-byte-budget-precheck (bf51fa4) to b231cf1 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: arrow_writer Comparing perf-byte-budget-precheck (bf51fa4) to b231cf1 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Comparison results: View the complete native critcmp output. The comparison is published in an unlisted Gist because the original inline report exceeded GitHub's comment limit. Per-runner informationarrow_writer — shard 1/4Node: gk3-benchmark-cluster-nap-17yz8u0s-c78dad10-hp78 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 2/4Node: gk3-benchmark-cluster-nap-r5b1bsxo-0e1bca2a-sz8x Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 3/4Node: gk3-benchmark-cluster-nap-17yz8u0s-dc2beb66-4t8b Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 4/4Node: gk3-benchmark-cluster-nap-r5b1bsxo-7fe87dcb-5l4n Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
@etseidl this should be ready |
|
Thanks @adriangb. Looked good to me 😅, but my agent found a nit. Review: changes requestedReviewed head P1 - Lookahead can disable page splitting for
|
| Result | Base | PR head |
|---|---|---|
| Data pages | 8 | 2 |
| Maximum page-body size | 1,048,604 bytes | 7,078,017 bytes |
Both files round-trip, but the PR packs all 27 large strings into one page. These are separate singleton records, not one indivisible oversized record.
Scaling those 27 strings to 76 MiB each would produce 2,151,677,952 payload bytes, exceeding the format's signed 32-bit page-size limit. That large-allocation case was not executed.
Why this belongs to this PR: the faulty span assumption predates the change, but the current chunk's indices are increasing and correctly sized on the base. Looking into later chunks introduces the backwards jump and creates this regression:
- Base sizes
[0, 1, ..., 27]and returns2, including the first overflowing value. - PR sizes
[0, 1, ..., 27, 0, ..., 0]and incorrectly returns1,024. - The PR therefore skips splitting the current chunk, violating the newly documented prefix contract.
Suggested correction: use the span shortcut only with a proven strictly increasing index sequence; fall back to cumulative sizing for reordered or repeated gathers. Add an Arrow-encoder regression with an increasing current-chunk prefix followed by reordered lookahead. The new tests use the generic slice encoder with identity indices and miss this case.
Reproducer
Save this as parquet/examples/listview_lookahead_repro.rs and run it on each revision:
# On base b231cf15efa5dbbbe4ae8503849aa6ab3cfc4e0c:
cargo run -p parquet --no-default-features --features arrow \
--example listview_lookahead_repro -- base /tmp/listview-base.parquet
# On PR head cf99e7ad168dd9c97f1aa2848ddea799c04498f5:
cargo run -p parquet --no-default-features --features arrow \
--example listview_lookahead_repro -- head /tmp/listview-head.parquetThe same source was tested through external Cargo projects using path dependencies on the two checkouts.
use std::{fs::File, sync::Arc};
use arrow_array::{Array, ListArray, ListViewArray, RecordBatch, StringArray};
use arrow_schema::{DataType, Field, Schema};
use parquet::{
arrow::{ArrowWriter, arrow_reader::ParquetRecordBatchReaderBuilder},
basic::{Compression, Encoding},
file::{
properties::WriterProperties,
reader::{FileReader, SerializedFileReader},
},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = std::env::args().collect();
let label = args.get(1).expect("revision label");
let output = args.get(2).expect("output parquet path");
const LARGE_BYTES: usize = 256 * 1024;
const PAGE_LIMIT: usize = 16 * 1024;
const BATCH_SIZE: usize = 1024;
const ROWS: usize = 2020;
// Child 0 is small; children 1..27 are large.
let mut strings = vec!["s".to_owned()];
for idx in 1..28 {
strings.push(
char::from(b'A' + (idx - 1) as u8)
.to_string()
.repeat(LARGE_BYTES),
);
}
let children = Arc::new(StringArray::from(strings));
let child_field = Arc::new(Field::new_list_field(DataType::Utf8, false));
let schema = Arc::new(Schema::new(vec![Field::new(
"lists",
DataType::ListView(child_field.clone()),
true,
)]));
// First chunk: children 0..27, then 996 null lists.
// Later rows: 996 singleton lists referencing child 0.
let offsets: Vec<i32> = (0..ROWS)
.map(|row| if row < 28 { row as i32 } else { 0 })
.collect();
let validity: Vec<bool> = (0..ROWS)
.map(|row| row < 28 || row >= BATCH_SIZE)
.collect();
let sizes: Vec<i32> = validity.iter().map(|valid| i32::from(*valid)).collect();
let lists = ListViewArray::new(
child_field,
offsets.into(),
sizes.into(),
children.clone(),
Some(validity.into()),
);
assert_eq!(lists.null_count(), 996);
let batch = RecordBatch::try_new(schema.clone(), vec![Arc::new(lists)])?;
let properties = WriterProperties::builder()
.set_dictionary_enabled(false)
.set_encoding(Encoding::PLAIN)
.set_compression(Compression::UNCOMPRESSED)
.set_data_page_size_limit(PAGE_LIMIT)
.set_write_batch_size(BATCH_SIZE)
.build();
let mut writer = ArrowWriter::try_new(File::create(output)?, schema, Some(properties))?;
writer.write(&batch)?;
writer.close()?;
println!(
"revision={label} rows={ROWS} large_values=27 \
large_value_bytes={LARGE_BYTES} page_limit={PAGE_LIMIT} \
write_batch_size={BATCH_SIZE}"
);
let file_reader = SerializedFileReader::new(File::open(output)?)?;
assert_eq!(file_reader.num_row_groups(), 1);
let row_group = file_reader.get_row_group(0)?;
let mut pages = row_group.get_column_page_reader(0)?;
let mut page_count = 0;
let mut max_page_bytes = 0;
while let Some(page) = pages.get_next_page()? {
assert!(page.is_data_page(), "dictionary unexpectedly enabled");
page_count += 1;
max_page_bytes = max_page_bytes.max(page.buffer().len());
println!(
"page={page_count} level_values={} body_bytes={}",
page.num_values(),
page.buffer().len(),
);
}
println!(
"summary data_pages={page_count} max_page_body_bytes={max_page_bytes}"
);
// Check every row's validity, singleton-list length, and string contents.
let reader = ParquetRecordBatchReaderBuilder::try_new(File::open(output)?)?
.with_batch_size(BATCH_SIZE)
.build()?;
let mut row = 0;
for decoded in reader {
let decoded = decoded?;
let array = decoded.column(0);
for local in 0..decoded.num_rows() {
let expected_valid = row < 28 || row >= BATCH_SIZE;
assert_eq!(!array.is_null(local), expected_valid, "row {row} validity");
if expected_valid {
let child = if let Some(lists) = array.as_any().downcast_ref::<ListArray>() {
lists.value(local)
} else if let Some(lists) = array.as_any().downcast_ref::<ListViewArray>() {
lists.value(local)
} else {
panic!("unexpected decoded type {:?}", array.data_type());
};
assert_eq!(child.len(), 1, "row {row} list length");
let string = child.as_any().downcast_ref::<StringArray>().unwrap();
let expected_idx = if row < 28 { row } else { 0 };
assert_eq!(
string.value(0),
children.value(expected_idx),
"row {row} child value",
);
}
row += 1;
}
}
assert_eq!(row, ROWS);
println!("roundtrip=OK checked_rows={row}");
Ok(())
}Observed page-body sizes:
Base:
page=1 level_values=4 body_bytes=786461
page=2 level_values=4 body_bytes=1048604
page=3 level_values=4 body_bytes=1048604
page=4 level_values=4 body_bytes=1048604
page=5 level_values=4 body_bytes=1048604
page=6 level_values=4 body_bytes=1048604
page=7 level_values=4 body_bytes=1048604
page=8 level_values=1992 body_bytes=4997
summary data_pages=8 max_page_body_bytes=1048604
roundtrip=OK checked_rows=2020
PR head:
page=1 level_values=1024 body_bytes=7078017
page=2 level_values=996 body_bytes=4994
summary data_pages=2 max_page_body_bytes=7078017
roundtrip=OK checked_rows=2020
cf99e7a to
b0057f7
Compare
|
run benchmark arrow_writer shards: 4 |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 4 (4 workers). Comparing perf-byte-budget-precheck (b0057f7) to b231cf1 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: arrow_writer Comparing perf-byte-budget-precheck (b0057f7) to b231cf1 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Comparison results: View the complete native critcmp output. The comparison is published in an unlisted Gist because the original inline report exceeded GitHub's comment limit. Per-runner informationarrow_writer — shard 1/4Node: gk3-benchmark-cluster-nap-1hv4dsl5-32a87493-vc7t Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 2/4Node: gk3-benchmark-cluster-nap-1hv4dsl5-32a87493-p9c2 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 3/4Node: gk3-benchmark-cluster-nap-1hv4dsl5-32a87493-ch7t Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 4/4Node: gk3-benchmark-cluster-nap-tnpun609-97f5d8c7-45p8 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
@etseidl fixed #11997 (comment) in 6fb0f2e |
|
run benchmark arrow_writer shards: 4 |
1 similar comment
|
run benchmark arrow_writer shards: 4 |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 4 (4 workers). Comparing perf-byte-budget-precheck (b0057f7) to b231cf1 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 4 (4 workers). Comparing perf-byte-budget-precheck (b0057f7) to b231cf1 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: arrow_writer Comparing perf-byte-budget-precheck (b0057f7) to b231cf1 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Comparison results: View the complete native critcmp output. The comparison is published in an unlisted Gist because the original inline report exceeded GitHub's comment limit. Per-runner informationarrow_writer — shard 1/4Node: gk3-benchmark-cluster-nap-1r3q3rn9-5591cf25-2wgf Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 2/4Node: gk3-benchmark-cluster-nap-1r3q3rn9-48c03b01-kcmn Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 3/4Node: gk3-benchmark-cluster-nap-1r3q3rn9-48c03b01-phjt Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 4/4Node: gk3-benchmark-cluster-nap-1r3q3rn9-063541a9-vh7j Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: arrow_writer Comparing perf-byte-budget-precheck (b0057f7) to b231cf1 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Comparison results: View the complete native critcmp output. The comparison is published in an unlisted Gist because the original inline report exceeded GitHub's comment limit. Per-runner informationarrow_writer — shard 1/4Node: gk3-benchmark-cluster-nap-1r3q3rn9-b7659f46-nzcw Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 2/4Node: gk3-benchmark-cluster-nap-1r3q3rn9-b7659f46-nzcw Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 3/4Node: gk3-benchmark-cluster-nap-1r3q3rn9-5591cf25-2wgf Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 4/4Node: gk3-benchmark-cluster-nap-1r3q3rn9-063541a9-vh7j Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
@etseidl could you take another look here? |
|
Yes, sorry, I've been swamped. I'll get to this either later today or first thing tomorrow. |
etseidl
left a comment
There was a problem hiding this comment.
Confirmed the issue previously raised is addressed. Just one documentation nit.
It seems like some of the benefit may have been lost with the last round of changes. I'd like to benchmark this some more locally.
| // common small-value case for both non-null and (sparse) nullable | ||
| // columns. | ||
| if last >= first { | ||
| // Stage 1: span upper bound. The span `offsets[last+1] - offsets[first]` |
There was a problem hiding this comment.
So the O(1) description is dropped here, but not at the calling site in count_values_within_byte_budget_gather, nor in the PR description.
|
@adriangb I had my agent do some benchmarks to verify a fix to the #11996 regression. It's report follows (if you haven't seen "Colossus: The Forbin Project" I highly recommend...I watched it many times as a kid and it's frighteningly still relevant 🤣). Thanks for this work. I ran a focused comparison and found useful gains, but also two repeatable regression cases worth addressing. Compared corrected base
Base/head output files matched byte-for-byte for these cases. These are bounded one-host results, not universal workload claims; the inline-View and clustered gains are real. Repair target: repeated work over overlapping lookaheadPlease inspect The gather window contains the next
Thus avoiding the definition-level scan can replace it with substantially more overlapping estimator work. The offset ordering change and expanded window have coupled costs; this does not isolate all the slowdown to ordering validation. Could you try avoiding expanded lookahead when estimating it requires a linear scan? A candidate is to retain speculative lookahead when a genuinely cheap conservative bound proves it fits, otherwise count the current chunk and size only its actual gather prefix. This is a direction to test, not a verified fix; please prefer the smallest measured change rather than a broad encoder redesign or unnecessary public API addition. Simply shrinking the speculative window cannot establish that the whole chunk fits. Preserve correctness and retest
For reproduction, use identical fixed-seed logical values/nulls for Utf8 and Utf8View: 1,048,576 rows, about 1% present (ours has 10,536), a 128-value ASCII alphabet, lengths 8 and 32. Explicit properties: uncompressed, writer version 1.0, page statistics, 1 MiB data/dictionary limits, 20,000-row page limit, write batch 1,024, one row group. Ensure the out-of-line View uses one shared backing buffer, not one small buffer per value. Generate input outside timing and write to a discard sink. Retest the table cases against the corrected base, plus random sparsity with write batch 64. Validate roundtrip and actual page/dictionary bodies separately, retaining the existing soft-limit/boundary allowances. Keep the chunker/placeholder tests, page/dictionary-cap tests (including clustered nulls), and both |
The byte-budget estimate for offset-buffer byte arrays bounds the payload by the offsets span from the first gather index to the last. That bound holds only for strictly increasing indices. A ListView can reference its child values in any order and more than once, so a gather such as [0, 1, ..., 8, 0] spans only value 0. The estimate then reports that everything fits, and the writer packs every large value into one page. Use the span bound only when the indices are strictly increasing, and fall back to the per-value walk otherwise. Add ArrowWriter regressions for a backward jump inside one chunk and for one past the chunk. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Raw ColumnWriter callers may pad a contiguous values slice with placeholder ByteArrays past the values their levels reference; sizing them panics. Restrict the lookahead window to gather indices, which always name real values, and keep counting the chunk's values first on the contiguous path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The offsets stage-1 check now verifies index order, which is linear in the number of indices. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The byte-budget chunker decides page boundaries from an estimate of the value bytes. The estimate has a different code path for each byte array representation and for sparse, clustered and mixed value sizes. No test pins the pages that those paths produce, so a change to the estimate can move page boundaries without a failure. Write the same logical column as Utf8, LargeUtf8 and Utf8View (one data buffer and many), with write batch sizes 64 and 1024 and with the dictionary on and off. Assert the largest page stays within the limit and that every representation produces the same page layout. The tests read only the written file, so they do not depend on the estimator. These tests pass before the following fix. They guard it. Co-Authored-By: Claude Fable 5.2 <[email protected]>
To skip the def-level scan, the chunker sized the next `chunk_size` gathered values and returned early if they fit the page budget. On a sparse column a chunk holds a few values, so the windows of consecutive chunks overlap almost entirely. A 99% null column with 1M rows visited about 1M indices where counting the values of each chunk first visits about 10k. A Utf8View column with one shared data buffer always fell through to the per-view scan and wrote much slower than main. Prove the fit from the length of the window and a per-value bound, so the proof reads no values. The encoder reports the bound once per write call through the new crate-internal `ColumnValueEncoder::max_value_bytes`. Only view arrays report one: the largest data buffer bounds every value. An offset array has no bound tighter than its whole payload unless the code reads every offset. When the encoder has no bound or the bound does not fit, the chunker counts the values of the chunk first and sizes only those. That is the control flow of main. The lookahead still pays off in two cases: a chunk with no values left to gather, and a view array whose bound fits (inline values or small data buffers). Random-sparse Utf8 and shared-buffer views get no gain. The strict-order check on gather indices from the earlier ListView fix still runs once per chunk, so those columns can stay a few percent slower than main. Written files are byte-identical to main and to the previous commit. Co-Authored-By: Claude Fable 5.2 <[email protected]>
e4ddfef to
908ab98
Compare
|
Amazing, thanks so much for helping get this across the line! |
|
@etseidl ping for merge before we get conflicts :) |
Which issue does this PR close?
Rationale for this change
ByteBudgetChunker::byte_budget_sub_batchcallschunk_def.value_count(...)before it asks the encoder whether the chunk's values fit the page budget. For nullable columns (Materializeddef levels) that call is an O(chunk_size) scan, and it runs on every chunk of every nullable byte-array column, even chunks far below the page limit.What changes are included in this PR?
The chunker now asks the encoder first, about the next
chunk_sizevalues. That window always contains the chunk's values as a prefix, because a chunk holds at mostchunk_sizevalues.count_values_within_byte_budget[_gather]counts how many leading values fit, so its answer for the window also answers for the chunk:Nonewithout scanning def levels. This is the common case, and it uses the existing stage-1 bounds. Those cost O(1) for view arrays and one ordered pass over the indices for offset arrays.k, the first value that overflows: only now runvalue_count. Ifk >= vals_in_chunkthe overflow is past this chunk, so the chunk fits. Otherwisekis the same answer the current code computes.The lookahead is used only on the gather path (
value_indices), which the arrow writer always uses, because every gather index names a real value. A contiguousvaluesslice from a rawColumnWritercaller may be padded with placeholderByteArrays past the values its levels reference, and those can't be sized. That path keeps counting the chunk's values first, as onmain.There are no new trait methods. An earlier revision of this PR added a byte-array-only
values_fit_within_byte_budget_gatherhook toColumnValueEncoder. This version reuses the existing count instead, and benchmarked the same.Are these changes tested?
New unit tests in
byte_budget_chunkercallpick_sub_batchdirectly, through both the contiguous and the gather entry points:Levelswindow as onmain;test_write_statistics_not_arrowintests/geospatial.rscaught this in CI).They pass on
mainas well, so they pin the behaviour tomain's. The second test fails if thek >= vals_in_chunkcheck is removed. The existing writer and page-size tests also pass.Benchmarks:
arrow_writer,/defaultprops, on a quiet GCE c3-standard-8. Each variant ran twice, interleaved, and the numbers below are the two runs:Every case except the sparse one is within noise.
perfonbyte_array_sparse_99pct_null:byte_budget_sub_batch(with the inlined def-level scan) drops from 10.2% to 0.6% of samples, andcount_values_within_byte_budget_gatherrises from 0.9% to 1.6%.Are there any user-facing changes?
No.
🤖 Generated with Claude Code