Skip to content

Commit bf826ab

Browse files
committed
Reduce iterations for codspeed, disable multithreading
1 parent a669a2a commit bf826ab

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

crates/ruff_benchmark/benches/ty_walltime.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use ::criterion::SamplingMode;
2+
use rayon::ThreadPoolBuilder;
23
use ruff_benchmark::criterion;
34

45
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
@@ -56,6 +57,8 @@ fn bench_project(
5657
);
5758
}
5859

60+
setup_rayon();
61+
5962
let setup_project = project.setup().expect("Failed to setup project");
6063

6164
let root = SystemPathBuf::from_path_buf(setup_project.path.clone()).unwrap();
@@ -77,11 +80,16 @@ fn bench_project(
7780

7881
let mut group = criterion.benchmark_group("project");
7982
group.sampling_mode(SamplingMode::Flat);
80-
group.sample_size(match size {
81-
Size::Small => 30,
82-
Size::Medium => 20,
83-
Size::Large => 10,
84-
});
83+
84+
if cfg!(feature = "codspeed") {
85+
group.sample_size(10);
86+
} else {
87+
group.sample_size(match size {
88+
Size::Small => 30,
89+
Size::Medium => 20,
90+
Size::Large => 10,
91+
});
92+
}
8593

8694
group.bench_function(setup_project.config.name, |b| {
8795
b.iter_batched_ref(
@@ -190,5 +198,21 @@ fn sympy(criterion: &mut Criterion) {
190198
bench_project(project, criterion, 13000, Size::Large);
191199
}
192200

201+
static RAYON_INITIALIZED: std::sync::Once = std::sync::Once::new();
202+
203+
fn setup_rayon() {
204+
// Initialize the rayon thread pool outside the benchmark because it has a significant cost.
205+
// We limit the thread pool to only one (the current thread) because we're focused on
206+
// where ty spends time and less about how well the code runs concurrently.
207+
// We might want to add a benchmark focusing on concurrency to detect congestion in the future.
208+
RAYON_INITIALIZED.call_once(|| {
209+
ThreadPoolBuilder::new()
210+
.num_threads(1)
211+
.use_current_thread()
212+
.build_global()
213+
.unwrap();
214+
});
215+
}
216+
193217
criterion_group!(project, colour_science, freqtrade, pandas, pydantic, sympy);
194218
criterion_main!(project);

0 commit comments

Comments
 (0)