-
Notifications
You must be signed in to change notification settings - Fork 763
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
Upcoming changes to PyO3's API in 0.21 #3382
Comments
I was somewhat enamoured with |
I could live with that, even if we have to rename it again in a nogil future. |
That's right, this might unnecessarily complicate things. My second least favourite was |
Yes I quite like |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@hkpeaks Please do not hijack this issue which is specific to the upcoming API changes. I you would like to discuss your experiments with us, please open a separate discussion. Thank you. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I propose that |
(We would still need a different |
What would the equivalent of |
The existing |
Ah. Well then, I'd never noticed that. Sorry for the noise! |
All good worth stating explicitly! |
I'm not sure if this qualifies as "API change", but I'd love for modules to have an |
One thing which I noted when implementing #3531 is that if multiple traits methods with the same name are applicable for one type we get ambiguity, and that would be the advantage of inherent methods. I think we are expecting to have a 1:1 mapping of traits to types so this should not be a problem. How I noticed this is because our (internal) |
Since we've got quite a few features and a couple of breaking changes beginning to take shape, I'm beginning to think it'll make sense to release 0.21 separate to (before?) this major API overhaul. In the meanwhile I'll continue to chip away at the implementations like #3572, so hopefully if this doesn't make it into 0.21 we can land alpha releases of 0.22 with this API change committed shortly after. |
Just a status update here: after discussion of #3668 the leaning in #3674 (comment) was that it makes sense to release this new API in 0.21, so for better or worse 0.21 is going to be quite a large release! |
PyO3 0.21 is released, this is now done. |
This change to PyO3 is great! I'm very excited by the prospect of an almost zero-cost but safe layer around the CPython API. While studying these changes and PyO3 in general, I wonder: why was Does gil-refs memory management have advantages over the new way? Or was it simpler to implement? Or just more obvious to come up with? Thanks! |
A great question. The GIL Refs design was made long ago (it predates me), and perhaps at the time it wasn't realised what the performance consequences were likely to be. You can find it in early commits to this repository but with very little discussion. GIL Refs main advantage was simplicity. The syntax |
Update: to avoid churn we have decided to keep
Py<T>
as-is and introduce the new API asBound<'py, PyAny>
. This naming can be revisited in future, but we have enough breaking changes with this 0.21 release that we do not wish to ship a wholesale rename at this point. (See #3674 (comment))The tracking issue of the remaining work to implement and make
Bound<'py, PyAny>
a public API is in #3684We are also building documentation at https://pyo3.rs/main/migration#from-020-to-021
This is a ticket to pin to give visibility to discussion and feedback of an overhaul we're considering for PyO3's API, projected for 0.21 release later this year.
TLDR; we plan to move types like
&'py PyAny
to be stored instead in a smart pointer typePy<'py, PyAny>
. The existingPy<T>
type will continue to exist, but renamed, maybe toPySend<T>
orPyStatic<T>
(name ideas welcome).The reason for doing this is because we believe this will offer a faster and lower memory usage API. The
&'py PyAny
types are reliant on an internal datastructure we call the "reference pool", and it's the cause of memory frustrations such as #1056. It's a thread-local datastructure, so it also has a performance overhead whenever it is accessed. From benchmarks in prototypes I think as much as 30% overhead can be removed when doing lots of operations with Python objects.There will be some work needed to migrate to this new API, mostly due to changes in ownership semantics. I think it may be possible to expose the existing
&'py PyAny
API in a separate crate (saypyo3_pool
, name to be bikeshed) to make migration easier.There has been a lot of thought put into this API design over a large span of time. We want to preserve as many existing semantics as possible as well as provide an as simple a migration path as possible from current PyO3 code. We want PyO3 to be as fast as possible while also being accessible to Python users coming to Rust for the first time.
For the discussion of the latest prototype of this new API, see #3361
All feedback and questions welcome.
The text was updated successfully, but these errors were encountered: