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

PyCFunction bound api #3800

Merged
merged 1 commit into from
Feb 6, 2024
Merged

Conversation

snuderl
Copy link
Contributor

@snuderl snuderl commented Feb 5, 2024

Part of #3684

Adds _bound versions of PyCFunction constructors.

@davidhewitt Any suggestions what to do with wrap_pyfunction? The change to update it to Bound is pretty minimal, but potentially breaking if people are using it outside the standard m.add_function(wrap_pyfunction!...) scenario

@snuderl snuderl force-pushed the PyCFunction-bound-api branch 2 times, most recently from 2acb33d to 721c921 Compare February 5, 2024 12:59
Copy link

codspeed-hq bot commented Feb 5, 2024

CodSpeed Performance Report

Merging #3800 will degrade performances by 15.02%

Comparing snuderl:PyCFunction-bound-api (aa3c938) with main (059e485)

Summary

⚡ 3 improvements
❌ 1 regressions
✅ 75 untouched benchmarks

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

Benchmarks breakdown

Benchmark main snuderl:PyCFunction-bound-api Change
sequence_from_list 355.6 ns 300 ns +18.52%
list_via_downcast 157.2 ns 185 ns -15.02%
not_a_list_via_downcast 242.8 ns 215 ns +12.92%
mapping_from_dict 327.8 ns 272.2 ns +20.41%

@snuderl snuderl marked this pull request as ready for review February 5, 2024 13:14
@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Feb 5, 2024
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, overall looks good to me! Just two small style requests...

Regarding wrap_pyfunction, I'm definitely open to trying to see what happens if we change it to return Bound<'py, PyCFunction>. I think that we would potentially need to change both PyModule::add_function and PyModuleMethods::add_function to just take Bound<'py, PyCFunction>.

That's breaking, but hopefully most users would never notice the change if they're using the standard pattern. We'd need to mention this in the migration guide where we also comment on how we made the same decision to change the return type of the intern! macro.

Definitely worth experimenting in its own PR, though.

src/impl_/pyfunction.rs Show resolved Hide resolved
src/types/function.rs Outdated Show resolved Hide resolved
@snuderl
Copy link
Contributor Author

snuderl commented Feb 6, 2024

Thanks, overall looks good to me! Just two small style requests...

Regarding wrap_pyfunction, I'm definitely open to trying to see what happens if we change it to return Bound<'py, PyCFunction>. I think that we would potentially need to change both PyModule::add_function and PyModuleMethods::add_function to just take Bound<'py, PyCFunction>.

That's breaking, but hopefully most users would never notice the change if they're using the standard pattern. We'd need to mention this in the migration guide where we also comment on how we made the same decision to change the return type of the intern! macro.

Definitely worth experimenting in its own PR, though.

Yup changes look pretty minimal. I'll open the PR once this gets merged.

BTW do you prefer for me to squash my commits when resolving PR comments so history ends up being a bit cleaner?

@davidhewitt
Copy link
Member

BTW do you prefer for me to squash my commits when resolving PR comments so history ends up being a bit cleaner?

Yes please! Sometimes it makes sense to arrange things into multiple commits for future readers and that's fine, but when they're just "review feedback" then we like squashing 👍

(Because we occasionally keep multiple commits GH merge queue doesn't let us squash automatically. But maybe we should consider changing this, and instead of we want multiple commits open multiple PRs 🤔)

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Looks great, thanks again 👍

@snuderl
Copy link
Contributor Author

snuderl commented Feb 6, 2024

BTW do you prefer for me to squash my commits when resolving PR comments so history ends up being a bit cleaner?

Yes please! Sometimes it makes sense to arrange things into multiple commits for future readers and that's fine, but when they're just "review feedback" then we like squashing 👍

(Because we occasionally keep multiple commits GH merge queue doesn't let us squash automatically. But maybe we should consider changing this, and instead of we want multiple commits open multiple PRs 🤔)

Squashed

@davidhewitt davidhewitt added this pull request to the merge queue Feb 6, 2024
Merged via the queue into PyO3:main with commit 030a618 Feb 6, 2024
36 of 38 checks passed
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

2 participants