Skip to content

Commit 38430b8

Browse files
committed
fix: validate unsigned AVX2 take indices
Use unsigned SIMD comparisons and masked gathers for bounds safety, retain scalar fallbacks for unsupported address ranges, and reduce validity masks once after the hot loop. Add regression coverage and a focused primitive-take benchmark. Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent f3d6795 commit 38430b8

3 files changed

Lines changed: 268 additions & 56 deletions

File tree

vortex-array/benches/take_primitive.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
//! Benchmarks comparing [`PVector`] take vs [`DictArray`] canonicalization.
5-
//!
6-
//! Both are tracked by number of indices/codes for fair comparison.
4+
//! Benchmarks for primitive take and [`DictArray`] canonicalization.
75
86
#![expect(clippy::cast_possible_truncation)]
97
#![expect(clippy::unwrap_used)]
108

119
use std::sync::LazyLock;
1210

1311
use divan::Bencher;
12+
use divan::counter::ItemsCount;
1413
use rand::distr::Uniform;
1514
use rand::prelude::*;
1615
use rand_distr::Zipf;
@@ -35,6 +34,26 @@ const VECTOR_SIZE: &[usize] = &[16, 256, 2048, 8192];
3534

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

37+
#[divan::bench(sample_count = 200)]
38+
fn primitive_take_u32(bencher: Bencher) {
39+
const NUM_INDICES: usize = 1_000_000;
40+
41+
let values = PrimitiveArray::from_iter(0u32..256).into_array();
42+
let indices =
43+
PrimitiveArray::from_iter((0..NUM_INDICES).map(|index| index as u32 & 255)).into_array();
44+
45+
bencher
46+
.counter(ItemsCount::new(NUM_INDICES))
47+
.with_inputs(|| (indices.clone(), SESSION.create_execution_ctx()))
48+
.bench_values(|(indices, mut ctx)| {
49+
values
50+
.take(indices)
51+
.unwrap()
52+
.execute::<PrimitiveArray>(&mut ctx)
53+
.unwrap()
54+
});
55+
}
56+
3857
// --- DictArray canonicalization benchmarks ---
3958

4059
#[divan::bench(args = NUM_INDICES, consts = VECTOR_SIZE, sample_count = 100_000)]

0 commit comments

Comments
 (0)