Skip to content

Commit 3f56b09

Browse files
chore: benchmark with execution context input (#7429)
Create execution context outside of benchmark hot loop --------- Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 1a56560 commit 3f56b09

8 files changed

Lines changed: 142 additions & 131 deletions

File tree

encodings/fastlanes/benches/canonicalize_bench.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ fn canonical_into_non_nullable(
7878
chunked.dtype().nullability(),
7979
chunk_len * chunk_count,
8080
);
81-
(chunked, primitive_builder)
81+
(chunked, primitive_builder, SESSION.create_execution_ctx())
8282
})
83-
.bench_refs(|(chunked, primitive_builder)| {
83+
.bench_refs(|(chunked, primitive_builder, ctx)| {
8484
chunked
85-
.append_to_builder(primitive_builder, &mut SESSION.create_execution_ctx())
85+
.append_to_builder(primitive_builder, ctx)
8686
.vortex_expect("append failed");
8787
primitive_builder.finish()
8888
});
@@ -114,8 +114,13 @@ fn into_canonical_nullable(
114114
.collect::<Vec<_>>();
115115

116116
bencher
117-
.with_inputs(|| ChunkedArray::from_iter(chunks.clone()).into_array())
118-
.bench_values(|chunked| chunked.execute::<Canonical>(&mut SESSION.create_execution_ctx()));
117+
.with_inputs(|| {
118+
(
119+
ChunkedArray::from_iter(chunks.clone()).into_array(),
120+
SESSION.create_execution_ctx(),
121+
)
122+
})
123+
.bench_values(|(chunked, mut ctx)| chunked.execute::<Canonical>(&mut ctx));
119124
}
120125

121126
#[cfg(not(codspeed))]
@@ -140,11 +145,11 @@ fn canonical_into_nullable(
140145
chunked.dtype().nullability(),
141146
chunk_len * chunk_count,
142147
);
143-
(chunked, primitive_builder)
148+
(chunked, primitive_builder, SESSION.create_execution_ctx())
144149
})
145-
.bench_refs(|(chunked, primitive_builder)| {
150+
.bench_refs(|(chunked, primitive_builder, ctx)| {
146151
chunked
147-
.append_to_builder(primitive_builder, &mut SESSION.create_execution_ctx())
152+
.append_to_builder(primitive_builder, ctx)
148153
.vortex_expect("append failed");
149154
primitive_builder.finish()
150155
});

encodings/fsst/benches/chunked_dict_fsst_builder.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ fn chunked_dict_fsst_canonical_into(
4949
) {
5050
let chunk = make_dict_fsst_chunks::<u16>(len, unique_values, chunk_count);
5151

52-
bencher.with_inputs(|| &chunk).bench_refs(|chunk| {
53-
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
54-
chunk
55-
.append_to_builder(builder.as_mut(), &mut SESSION.create_execution_ctx())
56-
.vortex_expect("append failed");
57-
builder.finish()
58-
})
52+
bencher
53+
.with_inputs(|| (&chunk, SESSION.create_execution_ctx()))
54+
.bench_refs(|(chunk, ctx)| {
55+
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
56+
chunk
57+
.append_to_builder(builder.as_mut(), ctx)
58+
.vortex_expect("append failed");
59+
builder.finish()
60+
})
5961
}
6062

6163
#[divan::bench(args = BENCH_ARGS)]

encodings/fsst/benches/fsst_like.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ fn bench_like(bencher: Bencher, fsst: &FSSTArray, pattern: &str) {
109109
let len = fsst.len();
110110
let arr = fsst.clone().into_array();
111111
let pattern = ConstantArray::new(pattern, len).into_array();
112-
bencher.bench_local(|| {
113-
Like.try_new_array(len, LikeOptions::default(), [arr.clone(), pattern.clone()])
114-
.unwrap()
115-
.into_array()
116-
.execute::<Canonical>(&mut SESSION.create_execution_ctx())
117-
.unwrap()
118-
});
112+
bencher
113+
.with_inputs(|| SESSION.create_execution_ctx())
114+
.bench_refs(|ctx| {
115+
Like.try_new_array(len, LikeOptions::default(), [arr.clone(), pattern.clone()])
116+
.unwrap()
117+
.into_array()
118+
.execute::<Canonical>(ctx)
119+
.unwrap()
120+
});
119121
}
120122

121123
#[divan::bench(args = [

vortex-array/benches/chunk_array_builder.rs

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,30 @@ static SESSION: LazyLock<VortexSession> =
3939
fn chunked_bool_canonical_into(bencher: Bencher, (len, chunk_count): (usize, usize)) {
4040
let chunk = make_bool_chunks(len, chunk_count);
4141

42-
bencher.with_inputs(|| &chunk).bench_refs(|chunk| {
43-
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
44-
chunk
45-
.append_to_builder(builder.as_mut(), &mut SESSION.create_execution_ctx())
46-
.vortex_expect("append failed");
47-
builder.finish()
48-
})
42+
bencher
43+
.with_inputs(|| (&chunk, SESSION.create_execution_ctx()))
44+
.bench_refs(|(chunk, ctx)| {
45+
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
46+
chunk
47+
.append_to_builder(builder.as_mut(), ctx)
48+
.vortex_expect("append failed");
49+
builder.finish()
50+
})
4951
}
5052

5153
#[divan::bench(args = BENCH_ARGS)]
5254
fn chunked_opt_bool_canonical_into(bencher: Bencher, (len, chunk_count): (usize, usize)) {
5355
let chunk = make_opt_bool_chunks(len, chunk_count);
5456

55-
bencher.with_inputs(|| &chunk).bench_refs(|chunk| {
56-
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
57-
chunk
58-
.append_to_builder(builder.as_mut(), &mut SESSION.create_execution_ctx())
59-
.vortex_expect("append failed");
60-
builder.finish()
61-
})
57+
bencher
58+
.with_inputs(|| (&chunk, SESSION.create_execution_ctx()))
59+
.bench_refs(|(chunk, ctx)| {
60+
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
61+
chunk
62+
.append_to_builder(builder.as_mut(), ctx)
63+
.vortex_expect("append failed");
64+
builder.finish()
65+
})
6266
}
6367

6468
#[divan::bench(args = BENCH_ARGS)]
@@ -74,16 +78,18 @@ fn chunked_opt_bool_into_canonical(bencher: Bencher, (len, chunk_count): (usize,
7478
fn chunked_varbinview_canonical_into(bencher: Bencher, (len, chunk_count): (usize, usize)) {
7579
let chunks = make_string_chunks(false, len, chunk_count);
7680

77-
bencher.with_inputs(|| &chunks).bench_refs(|chunk| {
78-
let mut builder = VarBinViewBuilder::with_capacity(
79-
DType::Utf8(chunk.dtype().nullability()),
80-
len * chunk_count,
81-
);
82-
chunk
83-
.append_to_builder(&mut builder, &mut SESSION.create_execution_ctx())
84-
.vortex_expect("append failed");
85-
builder.finish()
86-
})
81+
bencher
82+
.with_inputs(|| (&chunks, SESSION.create_execution_ctx()))
83+
.bench_refs(|(chunk, ctx)| {
84+
let mut builder = VarBinViewBuilder::with_capacity(
85+
DType::Utf8(chunk.dtype().nullability()),
86+
len * chunk_count,
87+
);
88+
chunk
89+
.append_to_builder(&mut builder, ctx)
90+
.vortex_expect("append failed");
91+
builder.finish()
92+
})
8793
}
8894

8995
#[divan::bench(args = BENCH_ARGS)]
@@ -99,16 +105,18 @@ fn chunked_varbinview_into_canonical(bencher: Bencher, (len, chunk_count): (usiz
99105
fn chunked_varbinview_opt_canonical_into(bencher: Bencher, (len, chunk_count): (usize, usize)) {
100106
let chunks = make_string_chunks(true, len, chunk_count);
101107

102-
bencher.with_inputs(|| &chunks).bench_refs(|chunk| {
103-
let mut builder = VarBinViewBuilder::with_capacity(
104-
DType::Utf8(chunk.dtype().nullability()),
105-
len * chunk_count,
106-
);
107-
chunk
108-
.append_to_builder(&mut builder, &mut SESSION.create_execution_ctx())
109-
.vortex_expect("append failed");
110-
builder.finish()
111-
})
108+
bencher
109+
.with_inputs(|| (&chunks, SESSION.create_execution_ctx()))
110+
.bench_refs(|(chunk, ctx)| {
111+
let mut builder = VarBinViewBuilder::with_capacity(
112+
DType::Utf8(chunk.dtype().nullability()),
113+
len * chunk_count,
114+
);
115+
chunk
116+
.append_to_builder(&mut builder, ctx)
117+
.vortex_expect("append failed");
118+
builder.finish()
119+
})
112120
}
113121

114122
#[divan::bench(args = BENCH_ARGS)]
@@ -124,13 +132,15 @@ fn chunked_varbinview_opt_into_canonical(bencher: Bencher, (len, chunk_count): (
124132
fn chunked_constant_i32_append_to_builder(bencher: Bencher, (len, chunk_count): (usize, usize)) {
125133
let chunk = make_constant_i32_chunks(len, chunk_count);
126134

127-
bencher.with_inputs(|| &chunk).bench_refs(|chunk| {
128-
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
129-
chunk
130-
.append_to_builder(builder.as_mut(), &mut SESSION.create_execution_ctx())
131-
.vortex_expect("append failed");
132-
builder.finish()
133-
})
135+
bencher
136+
.with_inputs(|| (&chunk, SESSION.create_execution_ctx()))
137+
.bench_refs(|(chunk, ctx)| {
138+
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
139+
chunk
140+
.append_to_builder(builder.as_mut(), ctx)
141+
.vortex_expect("append failed");
142+
builder.finish()
143+
})
134144
}
135145

136146
const CONSTANT_UTF8_BENCH_ARGS: &[(&str, usize, usize)] = &[
@@ -146,13 +156,15 @@ fn chunked_constant_utf8_append_to_builder(
146156
) {
147157
let chunk = make_constant_utf8_chunks(value, len, chunk_count);
148158

149-
bencher.with_inputs(|| &chunk).bench_refs(|chunk| {
150-
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
151-
chunk
152-
.append_to_builder(builder.as_mut(), &mut SESSION.create_execution_ctx())
153-
.vortex_expect("append failed");
154-
builder.finish()
155-
})
159+
bencher
160+
.with_inputs(|| (&chunk, SESSION.create_execution_ctx()))
161+
.bench_refs(|(chunk, ctx)| {
162+
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
163+
chunk
164+
.append_to_builder(builder.as_mut(), ctx)
165+
.vortex_expect("append failed");
166+
builder.finish()
167+
})
156168
}
157169

158170
fn make_constant_utf8_chunks(value: &str, len: usize, chunk_count: usize) -> ArrayRef {

vortex-array/benches/chunked_dict_builder.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ fn chunked_dict_primitive_canonical_into<T: NativePType>(
4040
{
4141
let chunk = gen_dict_primitive_chunks::<T, u16>(len, unique_values, chunk_count);
4242

43-
bencher.with_inputs(|| &chunk).bench_refs(|chunk| {
44-
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
45-
chunk
46-
.append_to_builder(builder.as_mut(), &mut SESSION.create_execution_ctx())
47-
.vortex_expect("append failed");
48-
builder.finish()
49-
})
43+
bencher
44+
.with_inputs(|| (&chunk, SESSION.create_execution_ctx()))
45+
.bench_refs(|(chunk, ctx)| {
46+
let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
47+
chunk
48+
.append_to_builder(builder.as_mut(), ctx)
49+
.vortex_expect("append failed");
50+
builder.finish()
51+
})
5052
}
5153

5254
#[divan::bench(types = [u32, u64, f32, f64], args = BENCH_ARGS)]
@@ -59,6 +61,6 @@ fn chunked_dict_primitive_into_canonical<T: NativePType>(
5961
let chunk = gen_dict_primitive_chunks::<T, u16>(len, unique_values, chunk_count);
6062

6163
bencher
62-
.with_inputs(|| chunk.clone())
63-
.bench_values(|chunk| chunk.execute::<Canonical>(&mut SESSION.create_execution_ctx()))
64+
.with_inputs(|| (chunk.clone(), SESSION.create_execution_ctx()))
65+
.bench_values(|(chunk, mut ctx)| chunk.execute::<Canonical>(&mut ctx))
6466
}

vortex-array/benches/dict_mask.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ fn bench_dict_mask(bencher: Bencher, (fraction_valid, fraction_masked): (f64, f6
6262
let filter_mask = filter_mask(len, fraction_masked, &mut rng);
6363
let session = VortexSession::empty();
6464
bencher
65-
.with_inputs(|| (&array, &filter_mask))
66-
.bench_refs(|(array, filter_mask)| {
67-
let mut ctx = session.create_execution_ctx();
65+
.with_inputs(|| (&array, &filter_mask, session.create_execution_ctx()))
66+
.bench_refs(|(array, filter_mask, ctx)| {
6867
array
6968
.clone()
7069
.mask(filter_mask.clone().into_array())
7170
.unwrap()
72-
.execute::<RecursiveCanonical>(&mut ctx)
71+
.execute::<RecursiveCanonical>(ctx)
7372
.unwrap()
7473
});
7574
}

0 commit comments

Comments
 (0)