~/talk

Write faster Python! Common performance anti patterns

Talkat PyCon US 2022 · 2022-04-27..05-03· [python]
slides:none on file

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

  1. 0:00Intro
  2. 1:00James Murphy talk
  3. 2:34How to improve performance
  4. 4:35Before you start
  5. 6:25Profilers
  6. 7:14Sampling profilers
  7. 7:39My favourite profilers
  8. 9:36Antipatterns
  9. 10:24linter
  10. 10:58Looping variants
  11. 13:48List comprehension
  12. 15:00Wrong types
  13. 18:08Example
  14. 19:49Reading the results
  15. 21:19tuple iterator
  16. 21:59unmutated collection
  17. 22:27calling too many functions
  18. 23:12a and b example
  19. 24:41Utility library
  20. 26:43Wrap up
  21. 29:14Outro
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.