Repository navigation
bench(ipc): cover LZ4 reader and writer buffer layouts - #11138
Conversation
Rich-T-kid
left a comment
There was a problem hiding this comment.
I think it would nice to do this for the writer benchmarks as well
| fn assert_lz4_compressed_buffers(batch: &RecordBatch, require_all_positive: bool) { | ||
| let mut dictionary_tracker = DictionaryTracker::new(false); | ||
| let mut write_context = IpcWriteContext::default(); | ||
| let options = lz4_options(); | ||
| let (_, encoded) = IpcDataGenerator::default() | ||
| .encode(batch, &mut dictionary_tracker, &options, &mut write_context) | ||
| .unwrap(); | ||
| let message = root_as_message(&encoded.ipc_message).unwrap(); | ||
| assert_eq!(message.header_type(), MessageHeader::RecordBatch); | ||
| let record_batch = message.header_as_record_batch().unwrap(); | ||
| let buffers = record_batch.buffers().unwrap(); | ||
| let mut compressed_buffers = 0; | ||
| for buffer in buffers { | ||
| let length = usize::try_from(buffer.length()).unwrap(); | ||
| if length == 0 { | ||
| continue; | ||
| } | ||
| let offset = usize::try_from(buffer.offset()).unwrap(); | ||
| let prefix_end = offset.checked_add(8).unwrap(); | ||
| assert!(prefix_end <= encoded.arrow_data.len()); | ||
| let prefix = i64::from_le_bytes(encoded.arrow_data[offset..prefix_end].try_into().unwrap()); | ||
| assert!(prefix == -1 || prefix > 0); | ||
| if prefix > 0 { | ||
| compressed_buffers += 1; | ||
| } | ||
| if require_all_positive { | ||
| assert!(prefix > 0); | ||
| } | ||
| } | ||
| assert!(compressed_buffers > 0); | ||
| } |
There was a problem hiding this comment.
I dont think we should be testing things in benchmark code
There was a problem hiding this comment.
Agreed. I removed the benchmark-only correctness and compression-layout verification helpers. The functional benchmark runs now exercise the existing read and write paths without extra setup assertions.
| fn lz4_options() -> IpcWriteOptions { | ||
| IpcWriteOptions::default() | ||
| .try_with_compression(Some(CompressionType::LZ4_FRAME)) | ||
| .unwrap() | ||
| } |
There was a problem hiding this comment.
nit: I think we should stick to the existing pattern in the file
group.bench_function("StreamReader/no_validation/read_10/zstd", |b| {
let buffer = ipc_stream(
IpcWriteOptions::default()
.try_with_compression(Some(CompressionType::ZSTD))
.unwrap(),
);There was a problem hiding this comment.
Agreed. The LZ4 cases now follow the existing inline IpcWriteOptions and setup pattern used by the ZSTD cases.
| group.bench_function("StreamWriter/write_10/fixed_size_binary_256", |b| { | ||
| let batch = create_fixed_size_binary_batch(1, 256); | ||
| let options = IpcWriteOptions::default(); | ||
| let stream = write_stream(&batch, options.clone()); | ||
| validate_stream(&stream, &batch); | ||
| let mut buffer = Vec::with_capacity(2 * 1024 * 1024); | ||
| b.iter(move || { | ||
| buffer.clear(); | ||
| write_stream_into(&mut buffer, &batch, options.clone()); | ||
| black_box(buffer.len()); | ||
| }) | ||
| }); | ||
|
|
||
| group.bench_function("StreamWriter/write_10/fixed_size_binary_256/lz4", |b| { | ||
| let batch = create_fixed_size_binary_batch(1, 256); | ||
| let options = lz4_options(); | ||
| let stream = write_stream(&batch, options.clone()); | ||
| validate_stream(&stream, &batch); | ||
| assert_lz4_compressed_buffers(&batch, true); | ||
| let mut buffer = Vec::with_capacity(2 * 1024 * 1024); | ||
| b.iter(move || { | ||
| buffer.clear(); | ||
| write_stream_into(&mut buffer, &batch, options.clone()); | ||
| black_box(buffer.len()); | ||
| }) |
There was a problem hiding this comment.
im a bit confused as to why were singling out fixed sized binary for these benchmarks. Why cant they be added to the mixed schema in create_batch()?
There was a problem hiding this comment.
Agreed. I removed the isolated fixed-size layouts and added one fixed-size binary field to the shared create_batch fixture used by equivalent reader and writer benchmarks.
Rich-T-kid
left a comment
There was a problem hiding this comment.
nice and simple 😄 , thank you @RanaPriyansh
ea4515d to
f316800
Compare
|
ci is failure is unrelated |
Which issue does this PR close?
Related to #11129. These benchmarks do not resolve the decoder initialization question.
Rationale for this change
The IPC reader and stream-writer benchmarks lacked equivalent mixed-schema LZ4 coverage.
What changes are included in this PR?
Add one mixed-schema LZ4 case for
StreamReaderand one forStreamWriter, matching the existing ZSTD benchmark patterns. The sharedcreate_batchfixture now includes a non-null fixed-size binary field. Each case reads or writes ten batches. Reader validation remains enabled; writer iterations finish the stream and reuse the output buffer.The benchmark setup uses the existing fixture and timed-loop structure. It does not add correctness checks or compression-layout assertions to benchmark setup. The fixed-size binary field is representative fixture coverage, not a separate layout experiment.
Are these changes tested?
The mixed LZ4 and ZSTD reader and writer cases passed Criterion functional mode. The corresponding uncompressed controls passed with no default features. Stable formatting, targeted reader and writer Clippy, and
arrow-ipcall-targets/all-features Clippy passed with Rust 1.98.1 on aarch64 macOS. Full workspace tests and Clippy were not run. No performance improvement is claimed.Are there any user-facing changes?
No library or API changes.
AI assistance generated the benchmark changes, executed checks, and assisted review.