[issue14373] C implementation of functools.lru_cache

Matt Joiner report at bugs.python.org
Mon Mar 26 12:53:34 CEST 2012


Matt Joiner <anacrolix at gmail.com> added the comment:

I've fixed the commenting, and cache_info use.

I've left the element management in pure C as it reduces memory use (56 bytes for 4 element list, vs. 16 for lru_cache_elem), and avoids ref counting overhead (3 refs per link, plus GC). The difference might become quite marked for very large caches. There's also a nice invariant that links the key to the cache dict, and the result object to the lru_cache_elem. I'm happy to change this if it doesn't matter.

My only concern now is the wrapping of the lru cache object. In the Python version, @wraps allows the lru_cache to masquerade as the wrapped function wrt str/repr. The C version is wrapped, but str/repr remain unchanged. Not sure if this is a problem.

----------
Added file: http://bugs.python.org/file25026/functools.lru_cache-in-c.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14373>
_______________________________________


More information about the Python-bugs-list mailing list