Skip to content

bench(ipc): cover LZ4 reader and writer buffer layouts - #11138

Merged
Rich-T-kid merged 6 commits into
apache:mainfrom
RanaPriyansh:bench/ipc-lz4-buffer-count
Oct 25, 2026
Merged

Rich-T-kid merged 6 commits into
apache:mainfrom
RanaPriyansh:bench/ipc-lz4-buffer-count

Conversation

@RanaPriyansh

@RanaPriyansh RanaPriyansh commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

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 StreamReader and one for StreamWriter, matching the existing ZSTD benchmark patterns. The shared create_batch fixture 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-ipc all-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.

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-ipc arrow-ipc crate labels Sep 19, 2026

@Rich-T-kid Rich-T-kid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would nice to do this for the writer benchmarks as well

@RanaPriyansh RanaPriyansh changed the title bench(ipc): cover LZ4 reader buffer layouts bench(ipc): cover LZ4 reader and writer buffer layouts Sep 19, 2026
Comment thread arrow-ipc/benches/ipc_reader.rs Outdated
Comment on lines +245 to +275
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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should be testing things in benchmark code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread arrow-ipc/benches/ipc_reader.rs Outdated
Comment on lines +220 to +224
fn lz4_options() -> IpcWriteOptions {
IpcWriteOptions::default()
.try_with_compression(Some(CompressionType::LZ4_FRAME))
.unwrap()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(),
        );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The LZ4 cases now follow the existing inline IpcWriteOptions and setup pattern used by the ZSTD cases.

Comment thread arrow-ipc/benches/ipc_writer.rs Outdated
Comment on lines +83 to +107
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());
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Rich-T-kid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice and simple 😄 , thank you @RanaPriyansh

@Rich-T-kid

Copy link
Copy Markdown
Contributor

ci is failure is unrelated

@alamb alamb added the Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days label Oct 22, 2026
@Rich-T-kid
Rich-T-kid enabled auto-merge October 25, 2026 23:02
@Rich-T-kid
Rich-T-kid added this pull request to the merge queue Oct 25, 2026
Merged via the queue into apache:main with commit a2c6898 Oct 25, 2026
21 checks passed
@Jefffrey Jefffrey added the development-process Internal changes; PRs with this label are excluded from changelog label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-ipc arrow-ipc crate development-process Internal changes; PRs with this label are excluded from changelog Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants