[issue9410] Add Unladen Swallow's optimizations to Python 3's pickle.

Antoine Pitrou report at bugs.python.org
Mon Sep 6 19:35:15 CEST 2010


Antoine Pitrou <pitrou at free.fr> added the comment:

Here is a patch. Benchmark numbers:

* dumps():

./python -m timeit -s "import pickle, io; d={(x, 'a'): x  for x in range(10000)}" "pickle.dumps(d)"

-> before: 100 loops, best of 3: 7.47 msec per loop
-> after: 100 loops, best of 3: 2.45 msec per loop

* loads():

./python -m timeit -s "import pickle, io; d={(x, 'a'): x  for x in range(10000)}; d=pickle.dumps(d)" "pickle.loads(d)"

-> before: 100 loops, best of 3: 12.1 msec per loop
-> after: 100 loops, best of 3: 2.62 msec per loop

* dump():

./python -m timeit -s "import pickle, io; d={(x, 'a'): x  for x in range(10000)}" "pickle.dump(d, io.BytesIO())"
-> before: 100 loops, best of 3: 13.2 msec per loop
-> after: 100 loops, best of 3: 2.54 msec per loop

* load():

./python -m timeit -s "import pickle, io; d={(x, 'a'): x  for x in range(10000)}; d=pickle.dumps(d)" "pickle.load(io.BytesIO(d))"
-> before: 100 loops, best of 3: 12.7 msec per loop
-> after: 100 loops, best of 3: 11.6 msec per loop


As you can see, load() doesn't really benefit from the buffering improvements. The three methods see quite massive speedups.

----------
Added file: http://bugs.python.org/file18778/pickle_optimizations4.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9410>
_______________________________________


More information about the Python-bugs-list mailing list