How “lru_cache” Can Make Your Functions Over 100X FASTER In Python

preview_player
Показать описание
In this video we will be learning about how we can use lru_cache from functools to drastically increase the performance of our functions in Python. When used correctly this will lead to a MASSIVE performance boost.

lru_cache documentation:

▶ Become job-ready with Python:

▶ Follow me on Instagram:

00:00 About lru_cache
00:42 How to use lru_cache
04:27 Cache information
05:50 Clearing the cache
06:24 More about lru_cache
07:29 Another example with lru_cache
09:58 Insane performance boost
10:20 More cache information
10:53 Documentation
11:14 Bye bye
Рекомендации по теме
Комментарии
Автор

you should also specify that the cache works with pure functions; if a function has side effects and those effects are "needed", then the cache will break the functionality

AlexCernat
Автор

I was just going to say that one of the best examples to show the usefulness of caching here is fibonacci numbers, but I'm glad that you went through that.

vorpal
Автор

I make python coding videos, so feel that I am (partly) qualified to tell you that you produce excellent videos.

You type hint python so well, that you should consider moving to a statically typed language !

darrenlefcoe
Автор

Thanks for the guides, man. They've helped me a lot in my projects. Hope you'll keep on making them!

cheesy_boya
Автор

hands down! the fibonacci example literally blew my mind, great video

vincentlaizer
Автор

Interesting! I can think of some uses for this already. Especially for some math functions

sadhappy
Автор

Fibonacci example was amazing one to demonstrate this module, love it. ❤
😎👌🏻
😄🕶️👌🏻

gauravsoni
Автор

First viewer and first like . Love the video . Well I've been doing python for 5 years and i know lru cache. But good one.

haisomeone
Автор

Damn!!! That's a huge improvement.

JuniorMenezes
Автор

Thank you! But will this not be on the expense of the storage? If there is like an infinity of diffrent possibilities will that not cause any memory problems? 🤓 What are the actual limits? And when is Iru_cache best used or when to avoid it? (a SQL based function?) Can we save/load the cache so it is there if the script is newly started?

KnightAmine
Автор

great. Now I see how my code will be running faster. I can already see a use for this. OMG python now just got better.

rugmaable
Автор

Your explanation is always fantastic..
one question - from where to get list of libraries available in python ?

starmscloud
Автор

These imports needs to be installed first?
Thank you!

higiniofuentes
Автор

Super useful for video game development.

SkyFly
Автор

Key is same input should result same output. Do not use random, time, uuid, sequence etc …. Deterministic functions in oracle

samable
Автор

How you are imported measure and you can share with that

tannaprasanthkumar
Автор

Nice speed up 😮and nice and simple.
But something can’t ever get infinitely faster, though 😊There’s this pesky thing called physical boundaries in our universe 😅

CallousCoder
Автор

Keep in mind that using caching might be opening pandora's box. There are several cache management issues that can occur...

manolomonetha
Автор

is it necessary to clear the cash in some point!? and why!?

brhoom.h
Автор

Making recusrive fibonacci viable, ansolutely disgusting :D

FireSnake