Python Memory Management and Tips Transcripts
Chapter: Investigating memory usage
Lecture: Profiling introduction

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In carpentry, there's a saying "measure twice, cut once", and something like that should probably apply to software.
0:08 When we think we need to make changes for improving our code, we should probably measure it before we go make those changes.
0:16 My experience has been that we are very, very bad at guessing exactly what is expensive and what is not in software.
0:24 Sometimes this has to do with memory, sometimes it has to do a CPU speed. Often there's a relationship between those things.
0:31 So in this section, we're going to talk about measuring memory usage and using tools to
0:37 exactly understand what's happening, and then we can make changes and see how they're improving.
0:42 And we did that in a coarse-grained way before with our report memory thing that we did, it said "well,
0:47 looks like the process gained this much memory from this step to that step",
0:52 but all we were actually doing is asking how much memory is the process using now, or how much resident memory are we using right now,
1:00 and that can change based on things that are not exactly to do with allocation.
1:05 We could have shared memory, other stuff could be happening in the operating system, the GC could be holding on to memory for a while,
1:12 Who knows? So what we're gonna do is we're going to use some tools to
1:15 go and investigate and get more precise numbers about exactly what and where and how we're using memory.

Talk Python's Mastodon Michael Kennedy's Mastodon