Rich-T-kid commented on code in PR #11138:
URL: https://github.com/apache/arrow-rs/pull/11138#discussion_r4057339711
##########
arrow-ipc/benches/ipc_reader.rs:
##########
@@ -174,16 +203,117 @@ fn criterion_benchmark(c: &mut Criterion) {
/// Return an IPC stream with 10 record batches
fn ipc_stream(options: IpcWriteOptions) -> Vec<u8> {
let batch = create_batch(8192, true);
+ ipc_stream_with_batch(&batch, options)
+}
+
+fn ipc_stream_with_batch(batch: &RecordBatch, options: IpcWriteOptions) ->
Vec<u8> {
let mut buffer = Vec::with_capacity(2 * 1024 * 1024);
let mut writer =
StreamWriter::try_new_with_options(&mut buffer,
batch.schema().as_ref(), options).unwrap();
for _ in 0..10 {
- writer.write(&batch).unwrap();
+ writer.write(batch).unwrap();
}
writer.finish().unwrap();
buffer
}
+fn lz4_options() -> IpcWriteOptions {
+ IpcWriteOptions::default()
+ .try_with_compression(Some(CompressionType::LZ4_FRAME))
+ .unwrap()
+}
Review Comment:
nit: I think we should stick to the existing pattern in the file
```rust
group.bench_function("StreamReader/no_validation/read_10/zstd", |b| {
let buffer = ipc_stream(
IpcWriteOptions::default()
.try_with_compression(Some(CompressionType::ZSTD))
.unwrap(),
);
```
##########
arrow-ipc/benches/ipc_reader.rs:
##########
@@ -174,16 +203,117 @@ fn criterion_benchmark(c: &mut Criterion) {
/// Return an IPC stream with 10 record batches
fn ipc_stream(options: IpcWriteOptions) -> Vec<u8> {
let batch = create_batch(8192, true);
+ ipc_stream_with_batch(&batch, options)
+}
+
+fn ipc_stream_with_batch(batch: &RecordBatch, options: IpcWriteOptions) ->
Vec<u8> {
let mut buffer = Vec::with_capacity(2 * 1024 * 1024);
let mut writer =
StreamWriter::try_new_with_options(&mut buffer,
batch.schema().as_ref(), options).unwrap();
for _ in 0..10 {
- writer.write(&batch).unwrap();
+ writer.write(batch).unwrap();
}
writer.finish().unwrap();
buffer
}
+fn lz4_options() -> IpcWriteOptions {
+ IpcWriteOptions::default()
+ .try_with_compression(Some(CompressionType::LZ4_FRAME))
+ .unwrap()
+}
+
+fn read_stream(buffer: &[u8]) {
+ let projection = None;
+ let mut reader = StreamReader::try_new(buffer, projection).unwrap();
+ for _ in 0..10 {
+ std::hint::black_box(reader.next().unwrap().unwrap());
+ }
+ assert!(reader.next().is_none());
+}
+
+fn validate_stream(buffer: &[u8], expected: &RecordBatch) {
+ let projection = None;
+ let mut reader = StreamReader::try_new(buffer, projection).unwrap();
+ for _ in 0..10 {
+ let actual = reader.next().unwrap().unwrap();
+ assert_eq!(&actual, expected);
+ }
+ assert!(reader.next().is_none());
+}
+
+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);
+}
Review Comment:
I dont think we should be testing things in benchmark code
##########
arrow-ipc/benches/ipc_writer.rs:
##########
@@ -63,6 +66,74 @@ fn criterion_benchmark(c: &mut Criterion) {
})
});
+ group.bench_function("StreamWriter/write_10/lz4", |b| {
+ let batch = create_batch(8192, true);
+ let options = lz4_options();
+ let stream = write_stream(&batch, options.clone());
+ validate_stream(&stream, &batch);
+ assert_lz4_compressed_buffers(&batch, false);
+ 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", |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());
+ })
Review 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()`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]