Speeding up function calls with lru_cache in Python
hackeregg.github.io
Speeding up function calls with lru_cache in Python
1–10 of 85 posts
Re: Speeding up function calls with lru_cache in Python
#2One line summary: Use lru_cache decorator
@functools.lru_cache(maxsize=31)
def fib(n):
Re: Speeding up function calls with lru_cache in Python
#3Caching the result is not speeding up function calls.
Re: Speeding up function calls with lru_cache in Python
#4I recently discovered that joblib can do something similar, both on disk and in memory: https://joblib.readthedocs.io/en/latest/memory.html
Re: Speeding up function calls with lru_cache in Python
#5Instead of the last quote in the article, I prefer this one (got it from [0])
>"There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors." – Martin Fowler
And there's plenty of similar articles, for example [1] [2]
[0] https://www.mediawiki.org/wiki/Naming_things
Re: Speeding up function calls with lru_cache in Python
#6One line summary: Use lru_cache decorator @functools.lru_cache(maxsize=31) def fib(n):
[deleted]
Re: Speeding up function calls with lru_cache in Python
#7Functools’ lru_cache also has good methods for getting more info about the cache’s utilisation (.cache_info() I think), which is quite helpful when found in logs.
Re: Speeding up function calls with lru_cache in Python
#8Caching the result is not speeding up function calls.
Author here.
Sorry, If it feels misleading. I have no intention to mislead anybody. If you can suggest alternative title, I am happy to change title.
Re: Speeding up function calls with lru_cache in Python
#9I recently discovered that joblib can do something similar, both on disk and in memory: https://joblib.readthedocs.io/en/latest/memory.html
This memoizes closures of functions, and lets them be executed on other processors? Does it support dependency tracking between memoized closures (incremental recomputation), or do I have to roll that, myself?
Re: Speeding up function calls with lru_cache in Python
#10Caching the result is not speeding up function calls.
It is, though. It doesn’t speed up function execution, but it literally speeds up the function call.