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
Support out-of-band pickling for builtin types #84895
3.13only security fixesperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
It would be nice (where possible) to support out-of-band pickling of builtin bytes-like types. This would allow binary data from these objects to be shipped along separately zero-copy and later reconstructed during unpickling.
It seems that bytes, bytearray, and array would be good candidates for this behavior. Not sure if mmap or memoryview would make sense as it might not be clear on how to reconstruct them during unpickling, but if someone sees a way those would be nice to support too.
To illustrate this a bit, here is the behavior with a bytes object today:
In [1]: import pickle
In [2]: b = b"abc"
In [3]: l = []
In [4]: p = pickle.dumps(b, protocol=5, buffer_callback=l.append)
In [5]: l
Out[5]: []
With this change, we would see this behavior instead:
In [1]: import pickle
In [2]: b = b"abc"
In [3]: l = []
In [4]: p = pickle.dumps(b, protocol=5, buffer_callback=l.append)
In [5]: l
Out[5]: [<pickle.PickleBuffer at 0x10efe7540>]
(This is my first Python bug submission. So apologies if I got turned around here. Please go easy on me :)
3.13only security fixesperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
Activity
jakirkham commentedon May 21, 2020
It would be nice (where possible) to support out-of-band pickling of builtin
bytes-like types. This would allow binary data from these objects to be shipped along separately zero-copy and later reconstructed during unpickling.It seems that
bytes,bytearray, andarraywould be good candidates for this behavior. Not sure ifmmapormemoryviewwould make sense as it might not be clear on how to reconstruct them during unpickling, but if someone sees a way those would be nice to support too.To illustrate this a bit, here is the behavior with a
bytesobject today:With this change, we would see this behavior instead:
(This is my first Python bug submission. So apologies if I got turned around here. Please go easy on me :)
iritkatriel commentedon Sep 11, 2022
See also #89467.