Skip to main content

Profiling Python Code

Python Libraries & Tooling
Club H
13:45 on 09 July 2024
180 minutes


During my talk at python users group meetup about using Linux perf profiling in python 3.12 I asked the audience how they find performance issues in their Python code. Out of all respondents:

  • More than half simply read the code and find issues with their eyes;
  • 10% don’t face such problems at all;
  • The rest use various profilers.

In this workshop, I would like to influence this distribution and for this.

At the beginning, we will consider the application of CPU profiling to find bottlenecks. We will see how convenient it is to read information with a large volume of reports. How we can first localize to problematic functions, and then to specific lines of code. We will be helped by tools such as pytest-benchmark, cProfile and line_profiler.

Next, it is worth separately considering the problem of memory consumption by our code in Python and looking for places where we do not release it with memory_profiler and py-spy.

Each workshop block will be accompanied by an example and a practical task that you can solve on your laptop. And along the way, ask questions, share results, and discuss the topic of the workshop with other participants and the presenter.

The speaker

Pavel Filonov

Pavel Filonov

Developed MaxPatrol SIEM at Positive Technologies. At Kaspersky: from a project about ML in industrial cybersecurity to the head of the DS department.

Now he is developing his own Data Science consulting. Speaker at various conferences. Teacher of online courses on the OTUS platform. Author of trainings on soft skills.