~/talk

Vectorization: How slow Python runs fast code

Talkat Python Web Conf 2023 · 2023-03-13..03-17· [python]
slides:none on file

Vectorization means using chunked numeric representations and bulk native routines so Python code runs C/Rust-speed on large arrays. Using numpy.sum on a 30 million–element array measures about 100x faster than a Python loop (loop ~1.5s, numpy ~0.03s in the demo). Watch for tradeoffs: creating temporaries (abs(array) then mean) doubles memory; use Numba for in-place loops or avoid per-item callbacks like pandas.map which reintroduce Python overhead.

AI-written summary · about

  1. 0:00Intro
  2. 0:13Why software speed matters
  3. 1:36Feedback cycle time matters
  4. 2:27The paradox of Python performance
  5. 2:59Arrays: a shared, fundamental data structure
  6. 4:12The vectorization solution
  7. 5:17An example: Same results...
  8. 7:01An example: ...different speed
  9. 8:39Talk is about CPython
  10. 11:32Iteration in CPython: slow!
  11. 12:25Doing math in Python: slow!
  12. 14:59Memory layout of C arrays
  13. 15:59Memory layout of Python lists
  14. 16:55Carray vs. Python list
  15. 17:47NumPy arrays: a better memory layout for numeric data
  16. 19:19Example: Summing one million integers
  17. 22:51What does "vectorization" mean?
  18. 24:47Digression: Single Instruction, Multiple Data (SIMD)
  19. 27:10Avoiding built-in Python objects: example
  20. 28:18Avoid iterating in Python
  21. 31:16Avoid calling back into Python
  22. 33:29Summary: Writing fast data processing code
~/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.