Make #wrap_pyfunction return a Bound value
Part of Part of https://github.com/PyO3/pyo3/issues/3684
This is a tehnically a breaking change. The diff is pretty simple though which hopefully means not many users would be impacted in practice. Thoughts?
CodSpeed Performance Report
Merging #3808 will degrade performances by 12.82%
Comparing snuderl:wrap_pyfunction-bound (0e43071) with main (030a618)
Summary
⚡ 5 improvements
❌ 1 regressions
✅ 73 untouched benchmarks
:warning: Please fix the performance issues or acknowledge them on CodSpeed.
Benchmarks breakdown
| Benchmark | main |
snuderl:wrap_pyfunction-bound |
Change | |
|---|---|---|---|---|
| ⚡ | not_a_list_via_downcast |
242.8 ns | 215 ns | +12.92% |
| ⚡ | mapping_from_dict |
327.8 ns | 272.2 ns | +20.41% |
| ❌ | f64_from_pyobject |
377.8 ns | 433.3 ns | -12.82% |
| ⚡ | sequence_from_list |
355.6 ns | 300 ns | +18.52% |
| ⚡ | extract_str_downcast_fail |
266.1 ns | 238.3 ns | +11.66% |
| ⚡ | extract_int_downcast_fail |
266.1 ns | 238.3 ns | +11.66% |
There might be an option to avoid the breakage for PyModule::add_function. I think we could return a "private" wrapper type around Bound<PyCFunction> in _wrap_pyfunction, which implements From conversions for both Bound and gil-ref, and then perform the Into conversion inside the wrap_pyfunction macro.
I think we resolved this with new tricks in #3897. Thanks @snuderl for kicking this off and sorry we ended up going in a different direction...