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)
| 292 | /// sliced, the underlying buffer may be much larger than what's referenced by |
| 293 | /// the slice. The optimization avoids hashing unreferenced elements. |
| 294 | fn 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"), |
nothing calls this directly
no test coverage detected
searching dependent graphs…