Write faster Python! Common performance anti patterns
summary
Starts with how to setup a sampler profiler (Austin/Scalene) and benchmark realistic inputs; then shows concrete refactors: hoist loop‑invariant expressions (example yields ~55% speedup), replace hot for‑loops with list/dict comprehensions (~23%), pick tuples/classes/slots instead of lists/dataclasses (custom classes can be ~50% faster), and eliminate tiny function calls in hot loops (one case cites ~65% overhead). Also notes the match statement is ~80% faster for sequences. Track regressions and aim for >10% wins.
AI-written summary · about
chapters (21)
- 0:00Intro
- 1:00James Murphy talk
- 2:34How to improve performance
- 4:35Before you start
- 6:25Profilers
- 7:14Sampling profilers
- 7:39My favourite profilers
- 9:36Antipatterns
- 10:24linter
- 10:58Looping variants
- 13:48List comprehension
- 15:00Wrong types
- 18:08Example
- 19:49Reading the results
- 21:19tuple iterator
- 21:59unmutated collection
- 22:27calling too many functions
- 23:12a and b example
- 24:41Utility library
- 26:43Wrap up
- 29:14Outro
related talks
01h 31mDebugging and profiling techniques
01h 12mFurious & Fast Python 7: Writing Fast Python Code
19mPython - best practices
28m"Performant Python"
57mPython and PyPy performance (not) for dummies
50mPerformance tricks learned from low level developers
59mMyths and fairy tales around Python performance
37mTuning Python applications can dramatically increase performance
