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 bound dict constructors & py.run variants #3716

Closed
wants to merge 1 commit into from

Conversation

davidhewitt
Copy link
Member

This is based on top of #3711

The second commit adds PyDict bound constructors. At the same time I also added Python::eval_bound, Python::run_bound, and py_run_bound!, because these APIs consume dictionaries and it's extremely churn heavy to change all of these. So to at least do the churn in a single hop, I've pushed it as a single commit.

Copy link

codspeed-hq bot commented Dec 30, 2023

CodSpeed Performance Report

Merging #3716 will degrade performances by 14.16%

Comparing davidhewitt:dict-constructors (8cd3133) with main (c54d897)

Summary

⚡ 1 improvements
❌ 6 regressions
✅ 73 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main davidhewitt:dict-constructors Change
extract_int_downcast_fail 266.1 ns 297.2 ns -10.47%
extract_str_downcast_fail 266.1 ns 297.2 ns -10.47%
extract_str_extract_fail 2.3 µs 2.6 µs -11.78%
extract_float_downcast_success 418.9 ns 474.4 ns -11.71%
list_via_extract 336.7 ns 392.2 ns -14.16%
extract_float_extract_success 408.9 ns 464.4 ns -11.96%
test_simple_py 34.7 µs 31.4 µs +10.67%

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Dec 31, 2023
@davidhewitt
Copy link
Member Author

The performance "regressions" here are because the benchmarks are now eagerly dropping the containers rather than leaving them on the pool. I'll try to adjust accordingly.

The iter_dict improvement of ~25% is pretty consistent with the sort of gains I've seen from this new API! 🎉

@davidhewitt davidhewitt force-pushed the dict-constructors branch 7 times, most recently from 99f3230 to 2e85fb3 Compare January 4, 2024 21:35
@davidhewitt davidhewitt marked this pull request as ready for review January 5, 2024 07:08
@davidhewitt
Copy link
Member Author

Ok, this one is now good to review. The performance regressions still reported are on the ns scale and I expect are sensitive to changes in inlining due to benchmark changes. I'm not bothered by those as they might get change again later, e.g. after #3706

The iter_dict performance gain, I'm pretty sure is a genuine improvement of using the new Bound API instead of the pool.

@adamreichold
Copy link
Member

99 changed files in the diff, 99 changed files,
review one, mark it as viewed, 98 changed files in the diff.

@davidhewitt
Copy link
Member Author

Yes, I agree, it's a horrible diff. If you've got any suggestions on ways to split it to help review, I'm very open to trying. The problem I found is that adding these constructors basically immediately forced either adding locals.as_gil_ref() or #[allow(deprecated)] on every of these py.run sites anyway, so this diff wasn't much larger and ultimately seemed clearer imo.

@davidhewitt
Copy link
Member Author

... maybe I can try to see what happens if I just do py.run and friends first, and save the dict constructors for a second review? Let me know if you'd like me to try that.

@davidhewitt
Copy link
Member Author

(And for what it's worth, I have a feeling that this is one of the largest single diff PRs that we might face. These ones are used in so many tests.)

@@ -566,6 +566,7 @@ impl<'v> crate::PyTryFrom<'v> for PySequence {
}

#[cfg(test)]
#[cfg_attr(not(feature = "gil-refs"), allow(deprecated))]
Copy link
Member Author

Choose a reason for hiding this comment

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

In terms of why some tests have this blanket applied to mod tests, I did this for files where the GIL Ref API is tested in some detail in the contained tests, mostly inside src/types directory. I think we want to keep the GIL Ref tests for coverage anyway, so my feelings were to just do this now as one way to keep churn down, and revisit these after 0.21 is pushed and we're heading towards 0.22.

@adamreichold
Copy link
Member

Please don't worry. Sometimes we'll just have to pull through. I will finish the review eventually. I also understand that it is mostly tests and the changes there are mechanical so I can skim those files. I guess I will focus on the "source" changes in the any case.

CHANGELOG.md Outdated Show resolved Hide resolved
@davidhewitt
Copy link
Member Author

I've just rebased this, sorry if that disrupts a partial review.

I'm going to push a separate PR in a second which adds PyDict::new_bound without the deprecation, as that'll allow us to use that in other PRs and also maybe allow us to incrementally cut away at this diff.

@davidhewitt
Copy link
Member Author

@Icxolu FYI I just rebased this; it contains py.run_bound and py.eval_bound as well as deprecation change for PyDict::new_bound . This is probably still too much to be reviewable in one PR. I don't know whether you want to chop this PR up, start fresh, or just review this one. Up to you 👍

@Icxolu
Copy link
Contributor

Icxolu commented Feb 5, 2024

Thanks for the ping, I must have overlooked this one. I give it a try to see if this can reasonably be split, otherwise we might have to review it like this.

@davidhewitt
Copy link
Member Author

davidhewitt commented Feb 5, 2024

I think one option is to merge the rest of the new _bound API additions here without adding deprecations, like I already did for PyDict::new_bound. That way the rest of the changes could be done one API at a time, or group of files at a time, etc...

@Icxolu
Copy link
Contributor

Icxolu commented Feb 6, 2024

So I have played around with this a little. I could split off Python::eval and Python::run each into their separate PR (each with ~200 lines changed) leaving this PR to switch the PyDict/IntoPyDict constructors. @davidhewitt What do you think about this?

@davidhewitt
Copy link
Member Author

I think that would be excellent, yes please! I can either take responsibility for rebasing this one or leave it to you to eventually replace this one too.

@davidhewitt
Copy link
Member Author

Closing with thanks to @Icxolu for splitting this up and making a much better end result 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants