Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions encodings/fastlanes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ _test-harness = ["dep:rand"]
name = "bitpacking_take"
harness = false

[[bench]]
name = "bitpacking_filter"
harness = false

[[bench]]
name = "canonicalize_bench"
harness = false
Expand Down
76 changes: 76 additions & 0 deletions encodings/fastlanes/benches/bitpacking_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

//! Measures selective filtering around the sparse extraction thresholds.

#![expect(clippy::cast_possible_truncation)]
#![expect(clippy::unwrap_used)]

use std::sync::LazyLock;

use divan::Bencher;
use divan::counter::ItemsCount;
use vortex_array::ArrayRef;
use vortex_array::IntoArray;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::validity::Validity;
use vortex_buffer::BufferMut;
use vortex_fastlanes::BitPackedData;
use vortex_mask::Mask;
use vortex_session::VortexSession;

fn main() {
divan::main();
}

static SESSION: LazyLock<VortexSession> = LazyLock::new(|| {
let session = vortex_array::array_session();
vortex_fastlanes::initialize(&session);
session
});

const NUM_ARRAY_CHUNKS: usize = 64;
// Keep the array density below the outer full-decode policy.
const NUM_SELECTED_CHUNKS: usize = 8;
const CHUNK_SIZE: usize = 1_024;
const LEN: usize = NUM_ARRAY_CHUNKS * CHUNK_SIZE;

// Selection counts around the sparse extraction threshold for 16-bit values.
const BIT_WIDTH: u8 = 16;

fn fixture(selected_per_chunk: usize) -> (ArrayRef, Mask) {
let values: BufferMut<u32> = (0..LEN)
.map(|index| (index % (1 << BIT_WIDTH)) as u32)
.collect();
let packed = BitPackedData::encode(
&PrimitiveArray::new(values.freeze(), Validity::NonNullable).into_array(),
BIT_WIDTH,
&mut SESSION.create_execution_ctx(),
)
.unwrap()
.into_array();

let indices = (0..NUM_SELECTED_CHUNKS).flat_map(|chunk| {
(0..selected_per_chunk)
.map(move |index| chunk * CHUNK_SIZE + index * CHUNK_SIZE / selected_per_chunk)
});
(packed, Mask::from_indices(LEN, indices))
}

#[vortex_bench_support::cpu_features]
#[divan::bench(args = [8, 64, 80])]
fn filter(bencher: Bencher, selected_per_chunk: usize) {
let (packed, mask) = fixture(selected_per_chunk);

bencher
.counter(ItemsCount::new(LEN))
.with_inputs(|| (mask.clone(), SESSION.create_execution_ctx()))
.bench_refs(|(mask, ctx)| {
packed
.filter(mask.clone())
.unwrap()
.execute::<PrimitiveArray>(ctx)
.unwrap()
});
}
50 changes: 50 additions & 0 deletions encodings/fastlanes/benches/bitpacking_take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
use std::sync::LazyLock;

use divan::Bencher;
use divan::counter::ItemsCount;
use mimalloc::MiMalloc;
use rand::RngExt;
use rand::SeedableRng;
use rand::distr::Uniform;
use rand::prelude::StdRng;
use vortex_array::ArrayRef;
use vortex_array::IntoArray as _;
use vortex_array::RecursiveCanonical;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::validity::Validity;
use vortex_buffer::Buffer;
use vortex_buffer::BufferMut;
use vortex_buffer::buffer;
use vortex_fastlanes::BitPackedArrayExt;
use vortex_fastlanes::BitPackedData;
use vortex_fastlanes::bitpack_compress::bitpack_to_best_bit_width;
use vortex_session::VortexSession;

Expand All @@ -36,6 +40,52 @@ static SESSION: LazyLock<VortexSession> = LazyLock::new(|| {
session
});

const NUM_ARRAY_CHUNKS: usize = 64;
// Keep the selected count below the outer full-decode policy.
const NUM_SELECTED_CHUNKS: usize = 8;
const CHUNK_SIZE: usize = 1_024;
const THRESHOLD_FIXTURE_LEN: usize = NUM_ARRAY_CHUNKS * CHUNK_SIZE;

// Selection counts around the sparse extraction threshold for 16-bit values.
const THRESHOLD_BIT_WIDTH: u8 = 16;

fn threshold_fixture(selected_per_chunk: usize) -> (ArrayRef, ArrayRef) {
let values: BufferMut<u32> = (0..THRESHOLD_FIXTURE_LEN)
.map(|index| (index % (1 << THRESHOLD_BIT_WIDTH)) as u32)
.collect();
let packed = BitPackedData::encode(
&PrimitiveArray::new(values.freeze(), Validity::NonNullable).into_array(),
THRESHOLD_BIT_WIDTH,
&mut SESSION.create_execution_ctx(),
)
.unwrap()
.into_array();

let indices = PrimitiveArray::from_iter((0..NUM_SELECTED_CHUNKS).flat_map(|chunk| {
(0..selected_per_chunk)
.map(move |index| (chunk * CHUNK_SIZE + index * CHUNK_SIZE / selected_per_chunk) as u32)
}))
.into_array();
(packed, indices)
}

#[vortex_bench_support::cpu_features]
#[divan::bench(args = [8, 64, 80])]
fn threshold(bencher: Bencher, selected_per_chunk: usize) {
let (packed, indices) = threshold_fixture(selected_per_chunk);

bencher
.counter(ItemsCount::new(indices.len()))
.with_inputs(|| (indices.clone(), SESSION.create_execution_ctx()))
.bench_refs(|(indices, ctx)| {
packed
.take(indices.clone())
.unwrap()
.execute::<RecursiveCanonical>(ctx)
.unwrap()
});
}

#[divan::bench]
fn take_10_stratified(bencher: Bencher) {
let values = fixture(65_536, 8);
Expand Down
Loading