News for hackers. Stuff that matters.
Re:Speeding up function calls with lru_cache in Python by Immortal333 on Sunday June 28, 2020 @11:14AM (#23669271)
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 by shankysingh on Sunday June 28, 2020 @11:18AM (#23669301)
Thanks for article

Just a side note: with Fibonacci + caching it solidly become Dynamic programming problem so Time complexity reduces from quadratic to o(n), IIRC .

There is a whole class of problems where recursion + memoization(caching) = Top Down Dynamic programming , The other way to Increase performance and actually reduce call stack in these class of problems including Fibonacci would be Bottom Up Dynamic Programming

Some gists I found on it https://gist.github.com/trtg/4662449

Re:Speeding up function calls with lru_cache in Python by akdas on Sunday June 28, 2020 @02:56PM (#23671131)
Plugging my own writing, but I did a deep dive on top-down vs. bottom-up dynamic programming on my blog: https://avikdas.com/2019/04/15/a-graphical-introduction-to-d...

The follow-up posts go into even more detail on individual problems that can be solved using either form of dynamic programming, including some real-world problems like content-aware image resizing.

Re:Speeding up function calls with lru_cache in Python by eindiran on Sunday June 28, 2020 @06:47PM (#23672676)
Thank you for the link, I enjoyed the post a lot. The drawings you've done add a lot to the explanation. Do you have any other deep dives you've done in the same style that you'd recommend?
Re:Speeding up function calls with lru_cache in Python by akdas on Monday June 29, 2020 @12:48AM (#23674438)
Thanks! I'm glad the drawings were helpful.

Most of my writing can be found at my blog (https://avikdas.com/), but here are some from the same dynamic programming series:

- Deep-dive into the Chain Matrix Multiplication Problem - https://avikdas.com/2019/04/25/dynamic-programming-deep-dive... - Real-world applications of DP: https://avikdas.com/2019/05/14/real-world-dynamic-programmin... and https://avikdas.com/2019/07/29/improved-seam-carving-with-fo... - Another real-world application, this time in machine learning - https://avikdas.com/2019/06/24/dynamic-programming-for-machi...

If you look on my blog, you'll also see my recent series is on scalability, things like read-after-write consistency and queues for reliability.

Re:Speeding up function calls with lru_cache in Python by Immortal333 on Sunday June 28, 2020 @11:23AM (#23669343)
Yes, I have mentioned DP in my article as just reference. The Purpose of article was to show that how easy it is to implement caching in python using lru_cache decorator which is in std lib. So, We don't have to install any 3rd party lib.
Re:Speeding up function calls with lru_cache in Python by shankysingh on Sunday June 28, 2020 @11:26AM (#23669376)
oh sorry , somehow I missed it :)
Re:Speeding up function calls with lru_cache in Python by anandoza on Sunday June 28, 2020 @12:18PM (#23669808)
the simple recursive solution is actually O(fib(n)), which is exponential
Re:Speeding up function calls with lru_cache in Python by Denvercoder9 on Sunday June 28, 2020 @11:36AM (#23669475)
I'd suggest something along the lines of "Speeding up functions [in Python] by caching results" :)
Re:Speeding up function calls with lru_cache in Python by fwip on Sunday June 28, 2020 @12:31PM (#23669920)
"python memoization in one line"

Edit: I don't actually have much of a problem with the article headline as it is now. It depends a lot on your target audience! For Hacker News, yeah, we know what memoization is because we learned it in CS 102, right after we learned about recursion.

But for a lot of people who would get the most value from the article, the word "memoization" isn't going to mean much, and wouldn't read the article.

Maybe something like: "Memoization in Python, or how I learned to speed up function calls in just one line"