pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

Make #wrap_pyfunction return a Bound value

Open snuderl opened this issue 2 years ago • 2 comments

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?

snuderl avatar Feb 07 '24 11:02 snuderl

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%

codspeed-hq[bot] avatar Feb 07 '24 11:02 codspeed-hq[bot]

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.

Icxolu avatar Feb 07 '24 18:02 Icxolu

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...

davidhewitt avatar Feb 28 '24 19:02 davidhewitt