[New-bugs-announce] [issue24483] Avoid repeated hash calculation in C implementation of functools.lru_cache()
Serhiy Storchaka
report at bugs.python.org
Sun Jun 21 14:34:02 CEST 2015
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 <report at bugs.python.org>
<http://bugs.python.org/issue24483>
_______________________________________
More information about the New-bugs-announce
mailing list