summaryrefslogtreecommitdiffstats
path: root/Lib/functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2017-09-05 00:47:53 (GMT)
committerGitHub <noreply@github.com>2017-09-05 00:47:53 (GMT)
commit550370957cb0e40bfc497174c95fee47d01de995 (patch)
treece749b979fb3350b73af01fa360eeb6885ec2cd0 /Lib/functools.py
parent759e30ec47048cb9835c62aaeac48748c8151390 (diff)
downloadcpython-550370957cb0e40bfc497174c95fee47d01de995.zip
cpython-550370957cb0e40bfc497174c95fee47d01de995.tar.gz
cpython-550370957cb0e40bfc497174c95fee47d01de995.tar.bz2
Add comment to explain the implications of not sorting keywords (#3331)
In Python 3.6, sorted() was removed from _make_key() for the lru_cache and instead rely on guaranteed keyword argument order preservation. This makes keyword argument handling faster but it also causes multiple callers with a different keyword argument order to be cached as separate items. Depending on your point of view, this is either a performance regression (increased number of cache misses) or a performance enhancement (faster computation of keys).
Diffstat (limited to 'Lib/functools.py')
-rw-r--r--Lib/functools.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 89f2cf4..0873f20 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -432,6 +432,10 @@ def _make_key(args, kwds, typed,
saves space and improves lookup speed.
"""
+ # All of code below relies on kwds preserving the order input by the user.
+ # Formerly, we sorted() the kwds before looping. The new way is *much*
+ # faster; however, it means that f(x=1, y=2) will now be treated as a
+ # distinct call from f(y=2, x=1) which will be cached separately.
key = args
if kwds:
key += kwd_mark