[issue42903] optimize lru_cache for functions with no arguments

2021-01-12 Thread Eugene Toder
Eugene Toder added the comment: @cache does not address the problem or any of the concerns brought up in the thread. Thread-safe @once is a nice idea, but more work of course. -- ___ Python tracker

[issue42903] optimize lru_cache for functions with no arguments

2021-01-12 Thread STINNER Victor
Change by STINNER Victor : -- nosy: -vstinner ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: FYI: The @cache decorator was added as a result of that discussion and the related on python-ideas. -- ___ Python tracker ___

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Eugene Toder
Eugene Toder added the comment: Ammar, thank you for the link. -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Ammar Askar
Ammar Askar added the comment: Additional discussion on the same topic on discourse: https://discuss.python.org/t/reduce-the-overhead-of-functools-lru-cache-for-functions-with-no-parameters/3956 -- nosy: +ammar2 ___ Python tracker

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: Some other thoughts: * A zero argument function that returns a constant is unlikely to ever be used in a tight loop. That would be pointless. * The @cache decorator is already 30% faster than calling an empty function. It's very cheap. * We really

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Eugene Toder
Eugene Toder added the comment: As you can see in my original post, the difference between @cache (aka @lru_cache(None)) and just @lru_cache() is negligible in this case. The optimization in this PR makes a much bigger difference. At the expense of some lines of code, that's true. Also,

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: Just use the new @cache decorator.ยน It's cleaner looking in code and already sets maxsize to None, making it perfect for your application. With respect to the proposed optimization, I'm sorry but further optimization of this already fast special case

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Roundup Robot
Change by Roundup Robot : -- keywords: +patch nosy: +python-dev nosy_count: 3.0 -> 4.0 pull_requests: +23023 stage: -> patch review pull_request: https://github.com/python/cpython/pull/24197 ___ Python tracker

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Eugene Toder
New submission from Eugene Toder : It's convenient to use @lru_cache on functions with no arguments to delay doing some work until the first time it is needed. Since @lru_cache is implemented in C, it is already faster than manually caching in a closure variable. However, it can be made even