-
-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pickle] Dump using the highest available protocol #261
base: master
Are you sure you want to change the base?
[pickle] Dump using the highest available protocol #261
Conversation
@@ -327,7 +327,7 @@ def _set(self, key, value, timeout=None): | |||
# I didn't found a good way to avoid pickling/unpickling if | |||
# key is smaller than chunksize, because in case or <werkzeug.requests> | |||
# getting the length consume the data iterator. | |||
serialized = pickle.dumps(value, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm uncertain why this was hardcoded as 2
.
While I am generally for this PR I am not sure if this might break some applications? |
@@ -102,7 +102,7 @@ def set(self, key, value, timeout=None): | |||
full_key = self.key_prefix + key | |||
content_type = "application/json" | |||
try: | |||
value = json.dumps(value) | |||
value = json.dumps(value, pickle.HIGHEST_PROTOCOL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pickle isn't used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies. I got a tad carried away.
@sh4nks regarding,
per here:
My take is that by using |
This PR ensures that all backends use the same protocol (the highest available) for pickling the payload to cache. Some backends currently use the default (4 for Python 3.8) whereas some use 2 and others use the highest protocol available (maximum of 5).
Per the
pickle
documentation,it seems there is merit in utilizing the highest available protocol for consistency and increased performance.
Note that it seems the protocol is encoded within the dumped object, i.e., one does not need to re-specify the protocol when loading via
pickle.loads(...)
, thus this should be a non-breaking change.