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
The default pickle protocol is 4 now. But shelve still uses the pickle protocol 3. Shouldn't it be bumped? Shouldn't shelve use pickle.DEFAULT_PROTOCOL by default?
Disadvantages:
This will make shelve files incompatible with Python 3.3 by default.
Protocol 4 adds 9 bytes of overhead in comparison with protocol 3. This can be too large for the shelve containing a lot of small objects. Maybe strip redundant frame header for small pickles?
Activity
serhiy-storchaka commentedon Jul 24, 2018
The default pickle protocol is 4 now. But shelve still uses the pickle protocol 3. Shouldn't it be bumped? Shouldn't shelve use pickle.DEFAULT_PROTOCOL by default?
Disadvantages:
This will make shelve files incompatible with Python 3.3 by default.
Protocol 4 adds 9 bytes of overhead in comparison with protocol 3. This can be too large for the shelve containing a lot of small objects. Maybe strip redundant frame header for small pickles?
vstinner commentedon May 27, 2020
I wrote a short script to see the impact of file size depending on the protocol:
---
Output with Python 3.9.0b1 (on Fedora 32):
---
== Short value ==
Protocol 0: 90112 bytes
Protocol 1: 94208 bytes
Protocol 2: 94208 bytes
Protocol 3: 94208 bytes
Protocol 4: 94208 bytes
Protocol 5: 94208 bytes
== Large value ==
Protocol 0: 139264 bytes
Protocol 1: 139264 bytes
Protocol 2: 139264 bytes
Protocol 3: 139264 bytes
Protocol 4: 98304 bytes
Protocol 5: 98304 bytes
---
For short string values, protocol 0 produces smaller files than protocol 1 and higher.
For large value, protocol 4 and higher produce smaller files than protocol 3 and lower.
marco-c commentedon Oct 28, 2020
I've opened #22751 to fix this, I know there was already a PR, but it seems to have been abandoned.
ZackerySpytz commentedon Oct 28, 2020
It has not been abandoned.
miss-islington commentedon Oct 29, 2020
New changeset df59273 by Zackery Spytz in branch 'master':
bpo-34204: Use pickle.DEFAULT_PROTOCOL in shelve (GH-19639)
df59273