-
Notifications
You must be signed in to change notification settings - Fork 769
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
deprecate PyDict::new
constructor
#3823
Conversation
CodSpeed Performance ReportMerging #3823 will degrade performances by 14.16%Comparing Summary
Benchmarks breakdown
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks yet again!
Just a couple of small things I'd like to see tweaked on this one. As per #3811 I've just enabled squash merges, so up to you if you want to force-push the update or just add a new commit on top. 👍
Have you got further pieces that you're interested in picking up next / do you want suggestions?
pyo3-benches/benches/bench_dict.rs
Outdated
@@ -22,14 +22,14 @@ fn iter_dict(b: &mut Bencher<'_>) { | |||
fn dict_new(b: &mut Bencher<'_>) { | |||
Python::with_gil(|py| { | |||
const LEN: usize = 50_000; | |||
b.iter(|| (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict(py)); | |||
b.iter(|| (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict_bound(py)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep the bechmark comparable, it would probably make sense to use iter_with_large_drop
:
b.iter(|| (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict_bound(py)); | |
b.iter_with_large_drop(|| (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict_bound(py)); |
Motivation: the GIL Ref &PyDict
will live until the with_gil
closure ends, so the way the benchmark has changed means that we're now measuring freeing the dict when we weren't before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
tests/test_frompyobject.rs
Outdated
dict.set_item("a", "test").expect("Failed to set item"); | ||
let f = Foo::extract(dict.as_ref()).expect("Failed to extract Foo from dict"); | ||
let f = Foo::extract_bound(dict.as_ref()).expect("Failed to extract Foo from dict"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think generally I prefer the turbofish style here, as it'll be less residual work when we tidy up FromPyObject
in the future:
let f = Foo::extract_bound(dict.as_ref()).expect("Failed to extract Foo from dict"); | |
let f = dict.extract::<Foo>().expect("Failed to extract Foo from dict"); |
and similar for a lot of other cases in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the ones related to my changes here (or would you like to also include the ones not relevant to the PyDict
conversion?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, let's just change them all? Sorry I missed these before 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added these as a separate commit
I'm open for suggestions 😃 |
Awesome 🚀 ! So here's a couple ideas:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 perfect, thanks!
Thanks for the suggestions! I think I will start with looking at the |
Great! I expect the two main files to dig around in will be |
Part of #3684, followup on #3817 and last piece of #3716.
This deprecates the deprecates the
PyDict::new
constructor. In the second commit I also updated the benchmarks to make use of the new APIs.