You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use out-of-band buffers for Python buffer protocol supporting objects #365
Yes, exactly. One way of punting the question is to decide to deserialize a memoryview by recreating a bytes object with similar content. But what if your memoryview was backed by e.g. a mmap'ed file?
Yeah that makes sense. I think in cloudpickle we have chosen to just use bytearray, but it makes sense this would be ambiguous generally and may not make sense outside of cloudpickle.
What about other objects like bytes, bytearray, array, etc. where we do know how to allocate for them? Does it make sense for CPython to support out-of-band buffer serialization for them or are there some issues there as well?
The one trick for performing out-of-band pickling of memoryviews is we would need access to the protocol version (as is the case with __reduce_ex__. A function won't work as we can't pass more arguments to the function when using the dispatch_table. Maybe we can workaround this constraint by using a method and accessing the protocol version via class state. Thoughts?
Activity
pierreglaser commentedon May 8, 2020
Sure. Is there any reason for why
CPythondoes not have amemoryviewreducer?jakirkham commentedon May 8, 2020
That's a good question. I don't know. @pitrou, do you know? 🙂
pitrou commentedon May 8, 2020
Because it's not obvious how to serialize a
memoryview.jakirkham commentedon May 8, 2020
Meaning we don't know what memory to use for backing it?
pitrou commentedon May 8, 2020
Yes, exactly. One way of punting the question is to decide to deserialize a memoryview by recreating a bytes object with similar content. But what if your
memoryviewwas backed by e.g. a mmap'ed file?jakirkham commentedon May 8, 2020
Yeah that makes sense. I think in cloudpickle we have chosen to just use
bytearray, but it makes sense this would be ambiguous generally and may not make sense outside of cloudpickle.What about other objects like
bytes,bytearray,array, etc. where we do know how to allocate for them? Does it make sense for CPython to support out-of-band buffer serialization for them or are there some issues there as well?pitrou commentedon May 8, 2020
It would certainly make sense indeed. But it's not necessarily trivial and someone has to do the work ;-)
(note that a memoryview may have been sliced or casted... of course, you could choose to forbid those cases, but you would still have to detect them)
jakirkham commentedon May 8, 2020
What challenges do you envision in implementing out-of-band serialization for those other objects?
(yeah that's fair. there is a lot the current implementation brushes under the rug ;)
jakirkham commentedon May 22, 2020
FWIW opened upstream issue ( https://bugs.python.org/issue40718 ) on serializing builtin
bytes-like types.jakirkham commentedon May 22, 2020
The one trick for performing out-of-band pickling of
memoryviews is we would need access to the protocol version (as is the case with__reduce_ex__. A function won't work as we can't pass more arguments to the function when using thedispatch_table. Maybe we can workaround this constraint by using a method and accessing the protocol version via class state. Thoughts?