-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Use CFFI for the pixel access object #248
Comments
Cool 👍 |
Is this a 2.2.0 or some other milestone target? |
@wiredfool Will this happen for 2.3.0? |
Maybe. I think I know what has to happen. |
Last call for 2.3.0! |
Ok, made some progress on this one. I'm able to read and write one pixel of an rgb image through cffi without segfaulting or going through the _imaging c API for the get pixel/put pixel part. |
Still some undones, but it nominally works. |
Time to merge? |
No. This demonstrates that it's possible. It's not complete, one of the tests is failing, documentation is iffy at best, and it hasn't proved that's it's any faster than the old version either. I don't expect that it'll be slower, it just hasn't been tested. |
The crux on this was that the ffi.buffer call returns new memory that it owns, and duplicating the memory is a non-starter for the pixel access methods. The bit that I was missing is that you can use This patch can be cut down pretty dramatically, as we probably don't need most of the parts of the ImageMemoryInstance object, we're just using xsize, ysize, and one of the image8/image32 pointers. (and possibly the image pointer). We can avoid creating an ImagingMemoryInstance object at all, and just use the one pointer that we need. |
Benchmarks:
py2.7:
So, a win for pypy, not so much for c-python. |
Those times are way too small for PyPy - please run it in a loop so the total is at least a second |
Ok, longer, running 5k iterations or 10 seconds:
py2.7
So, pypy is 2 OOM faster when running longer? I wonder if the JIT is optimizing something important out of the loop, since the entire benchmark reduces to a bunch of noops. |
And while I've got benchmarks on the brain, I'll note that test_image_point.py is really slow on pypy (2m6.9s) and not on cpython (.6 seconds). |
Updated lcms2 to 2.13
Hoisted from #67, post-close, with additional brain dumping.
@fijal said:
The crux that I see is that (IIRC) the data isn't necessarily in a continuous block. If it were, the raw data pointer would be easy.
The backbrain is thinking that the solution might be related to checking the strides from #224. If the data's not continuous, we can fall back to slow access.
If a cffi approach would work, we'd need to require cffi and libffi-dev, but it's really only necessary on pypy, and anyone doing this on pypy would likely be ok an additional dependency.
Docs are here: http://cffi.readthedocs.org/en/latest/index.html
It looks like this is what we'd need:
So, Assuming that I can get a pointer from something like PyLong_FromVoidPtr, this should give higher performance access to the pixel_access_object.
The text was updated successfully, but these errors were encountered: