Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add comment to explain the implications of not sorting keywords
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).
  • Loading branch information
rhettinger authored Sep 4, 2017
commit 6f2ce06e71eb1b26660261957778546cdefd988d
4 changes: 4 additions & 0 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down