-
Notifications
You must be signed in to change notification settings - Fork 770
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
migrate many FromPyObject
implementations to Bound
API
#3784
Conversation
CodSpeed Performance ReportMerging #3784 will degrade performances by 14.16%Comparing Summary
Benchmarks breakdown
|
a816799
to
9ca76d2
Compare
Apart from the known volatility on the |
8f4c441
to
d772303
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're here, it might be nice to rename all the named lifetimes ('source
, 's
, ...) to 'py
for clarity and consistency with the rest of the code base. This would also easy the transition to a future with a second lifetime in FromPyObject
.
Otherwise this looks good to me.
Thanks for the review; and yes, that's a great idea, I'll push that now as a separate commit. Have you got access to the approval button when reviewing? If not, perhaps I can look into setting that up and also labelling so you can also apply the |
a0d8dd8
to
0d4df9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think approving might work, I just was not sure if you want me to do that. I dont think I can edit the labels.
impl<'source> FromPyObject<'source> for Cow<'source, [u8]> { | ||
fn extract(ob: &'source PyAny) -> PyResult<Self> { | ||
impl<'py> FromPyObject<'py> for Cow<'py, [u8]> { | ||
fn extract(ob: &'py PyAny) -> PyResult<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was not moving this to extract_bound
intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there's a bit of complexity around Cow
, &str
and &[u8]
because they need to depend on the lifetime of the input &Bound
.
For 0.21 I don't want to touch them, they will just have to continue with the pool I think. In 0.22 or 0.23 we may have to remove their FromPyObject
implementations and implement PyFunctionArgument
for them. Or we keep the pool for a little longer as an internal only thing just for these three implementations.
The right long term solution will again be adding the second lifetime to FromPyObject
so we can implement these implementations correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uff, so this means that 0.21 will not be fully compatible with gevent
then?
I wonder if having something like Backed<T>
where T
is separate Rust type with inline storage (e.g. &[u8]
), but backed by a Python pointer would be able to solve this without adding a lifetime to the schema at the cost of a reference count bump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've wondered a little about some kind of Backed<T>
type too, but I haven't explored the practicalities of how that would actually be implemented. I'd marked that as a future feature in my head.
Uff, so this means that 0.21 will not be fully compatible with gevent then?
One option is to gate these FromPyObject
implementations on the gil-refs
feature. That would be a normal "additive" feature. Without the feature enabled we implement PyFunctionArgument
instead. I will add that as a bullet in the tracking issue and potentially will push it as a draft later.
(At least then if users follow our migration steps their code wouldn't break from this until they disable the gil-refs
feature.)
impl<'a> FromPyObject<'a> for &'a [u8] { | ||
fn extract(obj: &'a PyAny) -> PyResult<Self> { | ||
impl<'py> FromPyObject<'py> for &'py [u8] { | ||
fn extract(obj: &'py PyAny) -> PyResult<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to that for Cow
. (The Cow
one should maybe also move here?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly yes, similar to the above. I'll move the implementation here though 👍
Split from #3606
This is a series of mechanical transformations from
extract
toextract_bound
for mostFromPyObject
implementations across the codebase.The few which remain are mostly blocked on other PRs waiting for review, it'll be straightforward to follow up with those another time.