New submission from Serhiy Storchaka: There is a difference between Python and C implementations of functools.lru_cache(). Python implementation caches the hash of the key, C implementation doesn't. May be this is not too important (at least I have no an example that shows the benefit of caching the hash), but there is a place for possible optimization. Proposed patch uses private functions _PyDict_GetItem_KnownHash() and _PyDict_SetItem_KnownHash() to avoid the second calculating of the hash for new keys.
The hash is still calculated second time when the key is deleted from full cache. To avoid this _PyDict_DelItem_KnownHash() is needed. ---------- components: Library (Lib) files: clru_cache_known_hash.patch keywords: patch messages: 245593 nosy: ncoghlan, rhettinger, serhiy.storchaka priority: normal severity: normal stage: patch review status: open title: Avoid repeated hash calculation in C implementation of functools.lru_cache() type: performance versions: Python 3.6 Added file: http://bugs.python.org/file39758/clru_cache_known_hash.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24483> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com