This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Optimize pickling function dispatch in hot loops.
Type: performance Stage: resolved
Components: Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: alexandre.vassalotti Nosy List: alexandre.vassalotti, pitrou, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-04-18 09:37 by alexandre.vassalotti, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
optimize_save_dispatch.patch alexandre.vassalotti, 2013-04-18 09:37 review
Messages (7)
msg187230 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-04-18 09:37
I found through profiling that batch_list_exact and batch_dict_exact spent a fair amount of time looking up the pickling function. I have found a way to optimize the lookup using a simple heuristic that assume items in dicts and lists have often a common type. So we have save some time by jumping right to the pickling function we need. Here are the result of running the benchmarks:

### fastpickle ###
Min: 0.593904 -> 0.541918: 1.10x faster
Avg: 0.606811 -> 0.564606: 1.07x faster
Significant (t=10.18)
Stddev: 0.01061 -> 0.02733: 2.5760x larger
Timeline: http://tinyurl.com/bwbvw7j

### pickle_list ###
Min: 0.907891 -> 0.915905: 1.01x slower
Avg: 0.970537 -> 0.948349: 1.02x faster
Significant (t=2.08)
Stddev: 0.07107 -> 0.02526: 2.8136x smaller
Timeline: http://tinyurl.com/cmlymq7
msg187231 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-04-18 09:57
In addition, we could bring back the switch dispatch based on the first letter of the type name. It does seem to speed up things as well but as much as the type cache optimization.
msg187233 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-04-18 10:13
I found a bug in the pickle_list benchmark. These are the new results:

### fastpickle ###
Min: 0.603416 -> 0.542480: 1.11x faster
Avg: 0.628639 -> 0.575296: 1.09x faster
Significant (t=6.29)
Stddev: 0.03330 -> 0.04985: 1.4969x larger
Timeline: http://tinyurl.com/c7xm7p6

### pickle_list ###
Min: 0.366062 -> 0.317290: 1.15x faster
Avg: 0.391959 -> 0.331500: 1.18x faster
Significant (t=15.86)
Stddev: 0.02131 -> 0.01651: 1.2910x smaller
Timeline: http://tinyurl.com/cad2mkx
msg187241 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-18 12:14
Why did you add all those calls to PyMemoTable_Get?
msg187458 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-04-20 20:41
Are you asking why do we need to call both PyMemoTable_Get and memo_get? Or, why do we fetching the memo was moved to the save functions? For the former, there is no real reason. The extra call could be removed though profiling doesn't show this call as a hot spot.

If the latter, we need this because the patch allow save(), which is where the memo was fetched, to be skipped.
msg187473 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-20 22:19
Thanks for the explanation. I guess I don't like the code duplication that this patch adds. Perhaps a macro hiding the "memo_get" code blocks? Also, adding your explanation as a comment would be nice too.
msg204268 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-11-24 20:59
The patch is too complicated for too little.
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 61987
2013-11-24 20:59:07alexandre.vassalottisetstatus: open -> closed
resolution: rejected
messages: + msg204268

stage: patch review -> resolved
2013-04-20 22:19:15pitrousetmessages: + msg187473
2013-04-20 20:41:18alexandre.vassalottisetmessages: + msg187458
2013-04-18 12:14:13pitrousetmessages: + msg187241
2013-04-18 10:13:03alexandre.vassalottisetmessages: + msg187233
2013-04-18 09:57:12alexandre.vassalottisetnosy: + pitrou, serhiy.storchaka

messages: + msg187231
title: Optimize pickling function lookups in hot loops. -> Optimize pickling function dispatch in hot loops.
2013-04-18 09:37:48alexandre.vassalotticreate