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

allow from_py_with on function args to take a fn(&Bound) -> PyResult #3837

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Feb 14, 2024

Part of #3684

This allows the #[pyfunction] and #[pymethod] arguments to use Bound API extractors in #[pyo3(from_py_with = ...)]. I reused the internal Extractor implementation that I recently introduced in #3828. For now I left it where I added it initially, but if we like to move it to a different place or module, I can do that.

There is still a lot of old APIs surrounding this, but it might be better to tackle them separately.

Copy link

codspeed-hq bot commented Feb 14, 2024

CodSpeed Performance Report

Merging #3837 will degrade performances by 15.63%

Comparing Icxolu:from-py-with-pyfunction (1a4a44d) with main (0c12d91)

Summary

⚡ 1 improvements
❌ 3 regressions
✅ 75 untouched benchmarks

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

Benchmarks breakdown

Benchmark main Icxolu:from-py-with-pyfunction Change
mapping_from_dict 300 ns 355.6 ns -15.63%
f64_from_pyobject 461.1 ns 405.6 ns +13.7%
sequence_from_list 327.8 ns 383.3 ns -14.49%
sequence_from_tuple 232.8 ns 260.6 ns -10.66%

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, that was straightforward!

There is still a lot of old APIs surrounding this, but it might be better to tackle them separately.

If you mean the rest of extract_argument, I've got pretty much all of it in #3708. That's just blocked on #3802 and then I think it's finally mergeable. I'll try to update #3802 tonight, if my toddler ever settles down for bed... 🙃

@@ -20,7 +20,7 @@ impl<'a, T> From<fn(&'a PyAny) -> PyResult<T>> for Extractor<'a, '_, T> {
}

impl<'a, 'py, T> Extractor<'a, 'py, T> {
Copy link
Member

Choose a reason for hiding this comment

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

Given that Extractor should be just temporary code which we'll remove again when the GIL Ref API is dead and gone, I'm fine with leaving it here for now 👍

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Feb 14, 2024
@davidhewitt davidhewitt added this pull request to the merge queue Feb 14, 2024
Merged via the queue into PyO3:main with commit 9902633 Feb 14, 2024
37 of 40 checks passed
@Icxolu Icxolu deleted the from-py-with-pyfunction branch February 14, 2024 22:48
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