-
Notifications
You must be signed in to change notification settings - Fork 187
Speed up tuple/list access #486
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
base: master
Are you sure you want to change the base?
Conversation
src/fasttuples.jl
Outdated
|
|
||
| import Base: get! | ||
| function get!(ret::PyObject, o::PyObject, returntype::TypeTuple, k) | ||
| ret.o = @pycheckn ccall((@pysym :PyObject_GetItem), |
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.
You need to decref the old ret.o pointer if it is non-NULL. Probably write a copy!(o::PyObject, p::PyPtr) method to encapsulate this pattern.
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.
Yeah, good pick up, I was wondering about that.
1320f2a to
9f70333
Compare
|
Looks good to me. (Note that in the 0.7 version of PyCall, where I use getproperty, |
|
Right, so Line 274 in fb75b96
PyObject_GetAttrString with o and s
and for Lines 777 to 786 in fb75b96
Seems ok, though I'm not really seeing why moving to getproperty necessitates switching to 0-based Integer indexing? I'd just been imagining getproperty would be sugar for PyObject_GetAttrString. Maybe you have a motivating example, and/or I'm missing something? Anyway, some ideas for deprecation if you do go for it: You could put one of these warnings on (edit: the first call in a session to)
I think 1 is good only if a macro-based check for |
Because Also, in Julia 0.7 there is better support for 0-based arrays in general with the new |
b0fcd8e to
d058e01
Compare
with benchmarks
pydecref_ avoids the `o.o = PyPtr_NULL`, which isn't needed in `copy!(dest::PyObject, src::PyPtr)`
And add a couple of missing decrefs
d058e01 to
770591b
Compare
Accessing Python tuples with integer indices is common, e.g. for functions with multiple return values.
The ideas here are to add new methods
get(o::PyObject, returntype::TypeTuple, k::Int)- and also to add an equivalentget!(ret::PyObject, ...)which assigns the result toret, without creating a new PyObject.They use
:PyTuple_GetItemfrom the Python API, which takes an Int (py_ssize_t) rather than aPyObject*.Benchmarks on my machine, for mean times (which are most relevant for accessing return values of functions in a tight loop, since they include gc cost) are:
I think we should probably go with
getwpyisinst!, and also addunsafe_gettpl!as a separate function (it can segfault if you use a bad index).