Skip to content
Merged
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
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.

4 changes: 4 additions & 0 deletions encodings/pco/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ vortex-mask = { workspace = true }
vortex-session = { workspace = true }

[dev-dependencies]
divan = { workspace = true }
rstest = { workspace = true }
vortex-array = { workspace = true, features = ["_test-harness"] }
vortex-arrow = { workspace = true }

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

//! Scalar reads out of a PCO array. Cases are `(access_count, nullable, scattered)`; clustered
//! indices stay inside one page so a retained decode can be reused, scattered ones cross pages.

use std::sync::LazyLock;

use divan::Bencher;
use vortex_array::ArrayRef;
use vortex_array::IntoArray;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::validity::Validity;
use vortex_error::VortexExpect;
use vortex_pco::Pco;
use vortex_session::VortexSession;

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

const LEN: usize = 16_384;
const CASES: &[(usize, bool, bool)] = &[
(1, false, false),
(1024, false, false),
(1024, true, false),
(1024, false, true),
];

static SESSION: LazyLock<VortexSession> = LazyLock::new(vortex_array::array_session);

fn pco(nullable: bool) -> ArrayRef {
let validity = if nullable {
Validity::from_iter((0..LEN).map(|i| i % 11 != 0))
} else {
Validity::NonNullable
};
let input = PrimitiveArray::new(
(0..LEN)
.map(|i| u32::try_from(i / 16).vortex_expect("fixture values fit u32"))
.collect::<Vec<_>>(),
validity,
);
let mut ctx = SESSION.create_execution_ctx();
Pco::from_primitive(input.as_view(), 8, 1024, &mut ctx)
.vortex_expect("PCO compression")
.into_array()
}

fn indices(count: usize, scattered: bool) -> Vec<usize> {
let span = if scattered { LEN } else { 256 };
let base = if scattered { 0 } else { 4096 };
let mut seed = 42u64;
(0..count)
.map(|_| {
seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1);
base + ((seed >> 32) as usize % span)
})
.collect()
}

#[divan::bench(args = CASES)]
fn scalar_access(bencher: Bencher, (count, nullable, scattered): (usize, bool, bool)) {
let array = pco(nullable);
let indices = indices(count, scattered);
bencher
.with_inputs(|| (SESSION.create_execution_ctx(), Vec::with_capacity(count)))
.bench_refs(|(ctx, scalars)| {
for &index in &indices {
scalars.push(
array
.execute_scalar(index, ctx)
.vortex_expect("scalar access"),
);
}
});
}
Loading