Skip to content

Commit 9b68f5a

Browse files
committed
Measure lazy decimal casts separately from execution
Keep canonical and Widen inputs for lazy construction, and one end-to-end canonical cast for execution into i256 values. Avoid a second end-to-end case that overlaps the construction and execution coverage. Update the CodSpeed target count to match the nine cases. Signed-off-by: Connor Tsui <[email protected]>
1 parent c66cf7c commit 9b68f5a

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎scripts/codspeed_bench_counts.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"varbinview_try_new": 6,
7676
"varbinview_zip": 2,
7777
"widen": 17,
78-
"widen_decimal": 6
78+
"widen_decimal": 9
7979
},
8080
"vortex-buffer": {
8181
"allocation": 35,

‎vortex-array/benches/widen_decimal.rs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
//! Canonical execution is omitted because it only returns the existing array. Each iteration shares
99
//! value buffers and builds fresh arrays so cached statistics cannot remove the operation's work.
1010
//! [`WidenArray::encode_decimal`] selects the child buffers outside the timed region.
11+
//!
12+
//! Casts from precision 38 to 76 measure lazy construction for canonical and `Widen` inputs.
13+
//! A canonical-input cast also measures execution through the copy into `i256` values.
1114
1215
use std::fmt;
1316
use std::sync::LazyLock;
@@ -28,6 +31,7 @@ use vortex_array::arrays::DecimalArray;
2831
use vortex_array::arrays::Widen;
2932
use vortex_array::arrays::WidenArray;
3033
use vortex_array::arrays::widen::WidenArraySlotsExt;
34+
use vortex_array::builtins::ArrayBuiltins;
3135
use vortex_array::dtype::DType;
3236
use vortex_array::dtype::DecimalDType;
3337
use vortex_array::dtype::DecimalType;
@@ -124,6 +128,13 @@ fn widen_cases() -> Vec<Case> {
124128
.collect()
125129
}
126130

131+
fn cast_cases() -> Vec<Case> {
132+
cases()
133+
.into_iter()
134+
.filter(|case| case.precision == 38)
135+
.collect()
136+
}
137+
127138
impl fmt::Display for Case {
128139
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129140
write!(
@@ -260,3 +271,36 @@ fn execute(bencher: Bencher, case: Case) {
260271
|array, ctx| execute_canonical(Ok(array), ctx),
261272
);
262273
}
274+
275+
#[divan::bench(args = cast_cases())]
276+
fn cast_lazy(bencher: Bencher, case: Case) {
277+
let values = case.values();
278+
let target = DType::Decimal(DecimalDType::new(76, SCALE), Nullability::NonNullable);
279+
280+
bench_case(
281+
bencher,
282+
|| values.array(case),
283+
|array, _ctx| {
284+
array
285+
.cast(target.clone())
286+
.vortex_expect("a same-scale precision increase is valid")
287+
},
288+
);
289+
}
290+
291+
#[divan::bench]
292+
fn cast_execute(bencher: Bencher) {
293+
let case = Case {
294+
precision: 38,
295+
child_precision: 18,
296+
input: Input::Canonical,
297+
};
298+
let values = case.values();
299+
let target = DType::Decimal(DecimalDType::new(76, SCALE), Nullability::NonNullable);
300+
301+
bench_case(
302+
bencher,
303+
|| values.array(case),
304+
|array, ctx| execute_canonical(array.cast(target.clone()), ctx),
305+
);
306+
}

0 commit comments

Comments
 (0)