Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add benchmark for deferred object drops #4179

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions pyo3-benches/benches/bench_pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ fn drop_many_objects(b: &mut Bencher<'_>) {
});
}

fn deferred_drop_many_objects(b: &mut Bencher<'_>) {
b.iter_batched_ref(
|| Python::with_gil(|py| (0..1000).map(|_| py.None()).collect::<Vec<_>>()),
|objects| {
objects.clear();
// Trigger deferred drops
Python::with_gil(|_| {})
},
criterion::BatchSize::PerIteration,
);
}

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("drop_many_objects", drop_many_objects);
c.bench_function("deferred_drop_many_objects", deferred_drop_many_objects);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an argument against adding this benchmark, but I fear we will need a multi-threaded benchmark to really measure the coherence traffic effects. This will be painful to do as a microbenchmark, but I fear we will be missing the larger picture without it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, we will probably need a couple of multi threaded benchmarks to model different usage patterns. In the end I had less time today than I was hoping, but I might be able to do some tomorrow.

}

criterion_group!(benches, criterion_benchmark);
Expand Down
Loading