Write buffer protocol#356
Conversation
|
The idea sounds reasonable to me. However, we should just support buffer protocol instead of just support memoryview. As a result, |
b2bc2dd to
eaba2fc
Compare
|
@aisk thanks for your feedback. Here is a rework with the buffer protocol. I have also added few tests to check if both binary/cybinary can serialize few objects exposing the buffer protocol. |
bc0d690 to
3612db8
Compare
|
It is possible to pack it like that. But I have choose to write it in 2 steps instead. I guess it's better. |
33975fc to
09308ac
Compare
|
@aisk here the problem is that the pure python That's in between 2 worlds. I am thinking if it makes sens to propagate that at such place? Ill take a look anyway. |
Co-authored-by: AN Long <aisk@users.noreply.github.com>
09308ac to
50f11ef
Compare
I think it's OK to figure this out in the future. |
Hi,
This pull request features the
writebinary support for the Python buffer protocol.As result, on top of the already supported
strandbytes, the API now supportsbytearrayandmemoryview. Everything use the same new Cythonwrite_bufferfunction. Pure python writer was also implemented.This can be used to reduce a memory copy while using numpy arrays.
I don't have checked the result with a complex benchmark, but in my use case (arrays of about 16MB), i can notice a time reduction of about 10% in the average (client and server on the same machine). For small messages, this does not change anything. I don't really know what could be a good benchmark.
Actually i use it such way:
The pull request does not have any dependency to
numpy.Would you be interested by such contribution? Tell me the way i could improve it.