[Checkins] [zopefoundation/ZODB] 5eaf24: Use a higher pickle protocol (3) for serializing o...

GitHub noreply at github.com
Sat Aug 26 14:28:20 CEST 2017


  Branch: refs/heads/jam-pickle-prot
  Home:   https://github.com/zopefoundation/ZODB
  Commit: 5eaf2439cea58fbd2b9b5d64d561a9cfd07589fc
      https://github.com/zopefoundation/ZODB/commit/5eaf2439cea58fbd2b9b5d64d561a9cfd07589fc
  Author: Jason Madden <jamadden at gmail.com>
  Date:   2017-08-26 (Sat, 26 Aug 2017)

  Changed paths:
    M CHANGES.rst
    M src/ZODB/_compat.py
    M src/ZODB/blob.py

  Log Message:
  -----------
  Use a higher pickle protocol (3) for serializing objects on Python 2

Previously protocol 1 was used. This is more efficient for new-style
classes (all persistent objects are new-style), according to the docs,
at the cost of being very slightly less space efficient for old-style
classes.

In tests of a persistent object with two trivial numeric attributes,
the higher protocol was 12 bytes smaller, and serialized and
deserialized 1us faster. Introducing a reference to another new-style
class for a more realistic test made the higher protocol twice as fast
to serialize (20.5 vs 10.3us), almost half the size (215 vs 142
bytes), and it deserialized 30% faster (6.5 vs 4.6us).

On Python 2, this will now allow open ``file`` objects to be
pickled (loading the object will result in a closed file); previously
this would result in a ``TypeError`` (as does under Python 3). We had
tests that you couldn't do that with a BlobFile so I had to update it
to still make that true.

I wouldn't recommend serializing arbitrary open files under Python
2 (for one thing, they can't trivially be deserialized in Python 3),
but I didn't take any steps to prevent it either. Since this hasn't
been possible, there shouldn't be code in the wild that is trying to
do it---and it wouldn't be forward compatible with Python 3 either.




More information about the checkins mailing list