Skip to content

Commit

Permalink
1 benchy boi
Browse files Browse the repository at this point in the history
  • Loading branch information
a10y committed Jan 24, 2025
1 parent 2330277 commit fb0a9be
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bench-vortex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ tokio = { workspace = true, features = ["full"] }
uuid = { workspace = true, features = ["v4"] }
vortex = { workspace = true, features = ["object_store", "parquet"] }
vortex-datafusion = { workspace = true }
vortex-mask = { workspace = true }
xshell = { workspace = true }

[dev-dependencies]
Expand Down Expand Up @@ -105,3 +106,8 @@ harness = false
name = "clickbench"
test = false
harness = false

[[bench]]
name = "sel_vec"
test = false
harness = false
105 changes: 105 additions & 0 deletions bench-vortex/benches/sel_vec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#![allow(unused_imports, unused, dead_code)]
//! Various tests for the selection vector being present.
use criterion::{BenchmarkId, Criterion};
use rand::Rng;
use vortex::array::PrimitiveArray;
use vortex::compute::filter;
use vortex::dtype::{DType, Nullability, PType};
use vortex::encoding::{ArrayEncodingRef, Encoding};
use vortex::encodings::alp::{ALPArray, ALPEncoding};
use vortex::sampling_compressor::compressors::alp::ALPCompressor;
use vortex::sampling_compressor::compressors::bitpacked::{
BitPackedCompressor, BITPACK_WITH_PATCHES,
};
use vortex::sampling_compressor::compressors::EncodingCompressor;
use vortex::sampling_compressor::SamplingCompressor;
use vortex::variants::PrimitiveArrayTrait;
use vortex::{ArrayData, IntoArrayData, IntoCanonical};
use vortex_mask::Mask;

// criterion benchmark setup:
fn bench_sel_vec(c: &mut Criterion) {
let mut group = c.benchmark_group("filter_then_canonical");

// Run ALP + BitPacking.
let compressor = SamplingCompressor::default().including_only(&[
&ALPCompressor as &dyn EncodingCompressor,
&BITPACK_WITH_PATCHES,
]);

// Create a low-precision primitive array of f64
let arr = PrimitiveArray::from_iter((0..=65535).map(|x| (x as f64) * 0.2f64));
assert_eq!(arr.ptype(), PType::F64);

let arr = compressor
.compress(&arr.into_array(), None)
.unwrap()
.into_array();
assert_eq!(arr.encoding().id(), ALPEncoding::ID);

// Try for various mask
let max = 65536;
for selectivity in [0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999, 1.0] {
// Create a random mask of the given size
let true_count = (selectivity * max as f64) as usize;
// Create a randomized mask with the correct length and true_count.
let mask = create_mask(max, true_count);
assert_eq!(mask.len(), max);
assert_eq!(mask.true_count(), true_count);
group.bench_with_input(
BenchmarkId::from_parameter(selectivity),
&mask,
|b, mask| {
// Filter then into_canonical
b.iter(|| filter_then_canonical(&arr, &mask))
},
);
}
group.finish();

let mut group = c.benchmark_group("canonical_then_filter");
for selectivity in [0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999, 1.0] {
// Create a random mask of the given size
let true_count = (selectivity * max as f64) as usize;
// Create a randomized mask with the correct length and true_count.
let mask = create_mask(max, true_count);
group.bench_with_input(
BenchmarkId::from_parameter(selectivity),
&mask,
|b, mask| {
// Filter then into_canonical
b.iter(|| canonical_then_filter(&arr, &mask))
},
);
}
group.finish();
}

fn filter_then_canonical(array: &ArrayData, mask: &Mask) -> ArrayData {
let filtered = filter(array, mask).unwrap();
filtered.into_canonical().unwrap().into_array()
}

fn canonical_then_filter(array: &ArrayData, mask: &Mask) -> ArrayData {
let canonical = array.clone().into_canonical().unwrap().into_array();
filter(&canonical, mask).unwrap()
}

fn create_mask(len: usize, true_count: usize) -> Mask {
let mut mask = vec![false; len];
// randomly distribute true_count true values
let mut rng = rand::thread_rng();
let mut set = 0;
while set < true_count {
let index = rng.gen_range(0..len);
if !mask[index] {
mask[index] = true;
set += 1;
}
}
Mask::from_iter(mask)
}

criterion::criterion_group!(sel_vec, bench_sel_vec);
criterion::criterion_main!(sel_vec);

2 comments on commit fb0a9be

@a10y
Copy link
Contributor Author

@a10y a10y commented on fb0a9be Jan 24, 2025

Choose a reason for hiding this comment

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

Output on my M2

filter_then_canonical/0.001
                        time:   [21.584 µs 21.750 µs 21.986 µs]
                        change: [-9.5831% -8.9646% -8.3829%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
filter_then_canonical/0.01
                        time:   [46.108 µs 46.140 µs 46.175 µs]
                        change: [+0.3386% +0.6587% +0.9397%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe
filter_then_canonical/0.1
                        time:   [60.660 µs 61.072 µs 61.547 µs]
                        change: [-5.9625% -4.6879% -3.5463%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 17 outliers among 100 measurements (17.00%)
  6 (6.00%) high mild
  11 (11.00%) high severe
filter_then_canonical/0.5
                        time:   [165.39 µs 165.49 µs 165.60 µs]
                        change: [-9.9510% -8.8749% -7.9563%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild
filter_then_canonical/0.9
                        time:   [261.46 µs 266.28 µs 271.58 µs]
                        change: [+9.0973% +10.891% +13.088%] (p = 0.00 < 0.05)
                        Performance has regressed.
filter_then_canonical/0.99
                        time:   [243.22 µs 246.78 µs 250.26 µs]
                        change: [-8.4034% -7.2605% -6.0911%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 26 outliers among 100 measurements (26.00%)
  9 (9.00%) low severe
  2 (2.00%) low mild
  9 (9.00%) high mild
  6 (6.00%) high severe
filter_then_canonical/0.999
                        time:   [229.75 µs 236.01 µs 242.35 µs]
                        change: [-12.416% -10.213% -7.9367%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 20 outliers among 100 measurements (20.00%)
  3 (3.00%) high mild
  17 (17.00%) high severe
filter_then_canonical/1 time:   [46.486 µs 47.166 µs 47.886 µs]
                        change: [-8.5942% -7.3484% -6.2774%] (p = 0.00 < 0.05)
                        Performance has improved.

canonical_then_filter/0.001
                        time:   [46.848 µs 47.128 µs 47.481 µs]
                        change: [-0.3801% +0.7833% +1.9445%] (p = 0.20 > 0.05)
                        No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
canonical_then_filter/0.01
                        time:   [45.874 µs 45.971 µs 46.109 µs]
                        change: [+0.3851% +0.8122% +1.2794%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high severe
canonical_then_filter/0.1
                        time:   [61.602 µs 62.166 µs 62.692 µs]
                        change: [-0.0765% +0.9159% +1.8797%] (p = 0.07 > 0.05)
                        No change in performance detected.
canonical_then_filter/0.5
                        time:   [66.362 µs 67.415 µs 68.369 µs]
                        change: [-5.0632% -2.9553% -1.2874%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 19 outliers among 100 measurements (19.00%)
  6 (6.00%) low severe
  11 (11.00%) low mild
  2 (2.00%) high mild
canonical_then_filter/0.9
                        time:   [103.01 µs 104.02 µs 104.94 µs]
                        change: [-4.0715% -3.0572% -2.0760%] (p = 0.00 < 0.05)
                        Performance has improved.
canonical_then_filter/0.99
                        time:   [72.286 µs 72.600 µs 72.899 µs]
                        change: [+0.8697% +1.5070% +2.1066%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
canonical_then_filter/0.999
                        time:   [68.284 µs 68.670 µs 69.032 µs]
                        change: [-1.8399% -1.4029% -0.9885%] (p = 0.00 < 0.05)
                        Change within noise threshold.
canonical_then_filter/1 time:   [47.667 µs 48.282 µs 48.953 µs]
                        change: [-8.4827% -7.1502% -5.6771%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild

@a10y
Copy link
Contributor Author

@a10y a10y commented on fb0a9be Jan 24, 2025

Choose a reason for hiding this comment

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

I should note this is not using FoR compression, which means bitpacking may be very limited in effectiveness. Will rerun

Please sign in to comment.