Commit 55037095 authored by Raymond Hettinger's avatar Raymond Hettinger Committed by GitHub

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).
parent 759e30ec
...@@ -432,6 +432,10 @@ def _make_key(args, kwds, typed, ...@@ -432,6 +432,10 @@ def _make_key(args, kwds, typed,
saves space and improves lookup speed. 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 key = args
if kwds: if kwds:
key += kwd_mark key += kwd_mark
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment