From 781021ea5a5676662cfd1e7832b80372d93736df Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Thu, 7 Jan 2016 18:08:38 +0000 Subject: Use cPickle with Python 2 again, to fix v1.54 performance regression Some Python 3 compatibility changes made python-memcached import pickle rather than cPickle, since the latter isn't available on Python 3: https://github.com/linsomniac/python-memcached/commit/45403325e0249ff0f61d6ae449a7daeeb7e852e5 This is fine on Python 3, since importing pickle will automatically use the faster C implementation if available, however with Python 2 this caused a 400% slowdown in memcache gets between python-memcached v1.53 and v1.54, when dealing with objects other than bytes. This mostly fixes #71, though there is still a 10-20% performance drop using current master plus this change compared to v1.53 (using Python 2.7.10). --- memcache.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/memcache.py b/memcache.py index 5d97714..2fd452b 100644 --- a/memcache.py +++ b/memcache.py @@ -49,7 +49,6 @@ from __future__ import print_function import binascii import os -import pickle import re import socket import sys @@ -59,6 +58,12 @@ import zlib import six +if six.PY2: + # With Python 2, the faster C implementation has to be imported explicitly. + import cPickle as pickle +else: + import pickle + def cmemcache_hash(key): return ( -- cgit v1.2.1