MCPcopy Create free account
hub / github.com/apache/datafusion / sliced_array_benchmark

Function sliced_array_benchmark

datafusion/common/benches/with_hashes.rs:294–358  ·  view source on GitHub ↗

Benchmark sliced arrays to demonstrate the optimization for when an array is sliced, the underlying buffer may be much larger than what's referenced by the slice. The optimization avoids hashing unreferenced elements.

(c: &mut Criterion)

Source from the content-addressed store, hash-verified

292/// sliced, the underlying buffer may be much larger than what's referenced by
293/// the slice. The optimization avoids hashing unreferenced elements.
294fn sliced_array_benchmark(c: &mut Criterion) {
295 // Test with different slice ratios: slice_size / total_size
296 // Smaller ratio = more potential savings from the optimization
297 let slice_ratios = [10, 5, 2]; // 1/10, 1/5, 1/2 of total
298
299 for ratio in slice_ratios {
300 let total_rows = BATCH_SIZE * ratio;
301 let slice_offset = BATCH_SIZE * (ratio / 2); // Take from middle
302 let slice_len = BATCH_SIZE;
303
304 // Sliced ListArray
305 {
306 let full_array = list_array(total_rows);
307 let sliced: ArrayRef = Arc::new(
308 full_array
309 .as_any()
310 .downcast_ref::<ListArray>()
311 .unwrap()
312 .slice(slice_offset, slice_len),
313 );
314 c.bench_function(
315 &format!("list_array_sliced: 1/{ratio} of {total_rows} rows"),
316 |b| {
317 do_hash_test_with_len(b, std::slice::from_ref(&sliced), slice_len);
318 },
319 );
320 }
321
322 // Sliced MapArray
323 {
324 let full_array = map_array(total_rows);
325 let sliced: ArrayRef = Arc::new(
326 full_array
327 .as_any()
328 .downcast_ref::<MapArray>()
329 .unwrap()
330 .slice(slice_offset, slice_len),
331 );
332 c.bench_function(
333 &format!("map_array_sliced: 1/{ratio} of {total_rows} rows"),
334 |b| {
335 do_hash_test_with_len(b, std::slice::from_ref(&sliced), slice_len);
336 },
337 );
338 }
339
340 // Sliced Sparse UnionArray
341 {
342 let full_array = sparse_union_array(total_rows);
343 let sliced: ArrayRef = Arc::new(
344 full_array
345 .as_any()
346 .downcast_ref::<UnionArray>()
347 .unwrap()
348 .slice(slice_offset, slice_len),
349 );
350 c.bench_function(
351 &format!("sparse_union_sliced: 1/{ratio} of {total_rows} rows"),

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
do_hash_test_with_lenFunction · 0.85
map_arrayFunction · 0.85
sparse_union_arrayFunction · 0.85
sliceMethod · 0.80
list_arrayFunction · 0.70
as_anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…