deprecate PyDict::new constructor#3823
Conversation
CodSpeed Performance ReportMerging #3823 will degrade performances by 14.16%Comparing Summary
Benchmarks breakdown
|
davidhewitt
left a comment
There was a problem hiding this comment.
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
| 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.
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.
tests/test_frompyobject.rs
Outdated
| let dict = PyDict::new_bound(py); | ||
| 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.
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.
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.
Ah, let's just change them all? Sorry I missed these before 🤦
There was a problem hiding this comment.
I've added these as a separate commit
I'm open for suggestions 😃 |
Awesome 🚀 ! So here's a couple ideas:
|
|
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::newconstructor. In the second commit I also updated the benchmarks to make use of the new APIs.