Python Memory Management and Tips Transcripts
Chapter: Course conclusion and review
Lecture: Profiling

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw that we can investigate the memory used by our program in different ways: as a picture over time, line by line, by peak memory usage,
0:09 all those things. And We looked at two profilers: memory_Profiler and Fil. Fil's the one that measures the peak stuff best.
0:17 And this one here, memory_profiler, let's us ask questions about line by line. So we add this decorator out of the library, and then when we run it,
0:26 we just say "Python -m memory_profiler", give it the script, or the application to run, and the arguments, it's a little bit slower. Well,
0:34 it's a lot slower, but, you know, let it run and then out comes this really nice report of exactly how much memory was used by each line,
0:42 what was gained, what was lost and so on. So if you're worried about memory, take the time to stop and look.
0:48 Ask these tools "what's going on?" because there might be some part where you think "I need to optimize here", but it's actually some other line,
0:55 like something really simple, like, "Oh, we're doing slicing" and it seems really minor,
1:00 but that actually makes a copy a bunch of times and turns out to be real expensive or something along those lines.
1:05 Have a look with the tools that we showed you and investigate what your app is
1:09 doing and then apply some of the techniques that we've talked about to make it better.


Talk Python's Mastodon Michael Kennedy's Mastodon