~/talk

Python performance Past, Present, Future

Talkat PyCon India 2020 · 2020-10-02..10-05· [python]
slides:none on file

History shows many Python-VM efforts fail but some concrete wins exist: PyPy ≈4× faster on average but uses more memory and slower startup; C/ Rust extensions and Cython (avoid the CPython C-API) speed hot functions; Numba accelerates NumPy with vectorization and GPU backends; Python 3.8 adds shared memory and pickle protocol 5 for multiprocessing; HPy (handle-based C API) rewrites a JSON parser and gets ~4× speed on PyPy; Gilectomy experiments slow down, sub-interpreters and tracing GC remain promising.

AI-written summary · about

  1. 0:00Intro
  2. 1:12Python Implementations • 1989: CPython (Guido van Rossum) • 1997: Jython (Jim Hugunin) • 1998: Stackless Python Christian
  3. 10:11Competition with CPython CPython has around 30 active core developers to maintain it • New features first land into CPython • Why would users prefer an outdated and incompatible implementation? • Who will sponsor the development?
  4. 12:14Unladen Swallow (2011) • "Most Python code at Google isn't performance critical* "deployment was too difficult: being a replacement was not enough." "Our potential customers eventually found other ways of solving their performance problems. unladen-swallow-retrospective.html
  5. 15:19Summary CPython remains the reference implementation but shows its age • Multiple optimization projects failed PyPy: drop-in replacement, 4.4x faster, but not widely adopted yet: why?
  6. 16:25PyPy just works! • Drop-in replacement for CPython! • 4.4x faster than CPython in average (exact speedup depends on your workflow) • Fully compatible with CPython
  7. 23:59CPython: multiprocessing Process Thread Maths (CPU bound) Process
  8. 25:15Multiprocessing • Work around the GIL limitation Shared memory (Python 3.8) avoids memory copies between workers • New pickle version 5 (Python 3.8) avoids copying large objects: PEP 574
  9. 26:49Cython • Easy way to write C extension • Syntax similar to Python Support multiple Python versions • Handle reference counting for you • The optimizer emits efficient code using CPython internals for you
  10. 29:23Numba • JIT compiler translating subset of Python and NumPy into fast code • Simplified Threading: release GIL SIMD Vectorization: SSE, AVX, AVX-512 • GPU Acceleration: NVIDIA'S CUDA and AMD's ROCm
  11. 37:04Stable ABI • Support multiple Python versions: Python 3.8, 3.9,.. CPython 3.8 debug build is ABI compatible with the release build • It can use C extensions compiled in release mode • It has much more sanity checks at runtime to detect bugs
  12. 48:10New PyHandle C API CPython: Implemented on top of the current C API PyPy: More efficient than the current CAPI Cython: no need to change your code, Cython will generate code using PyHandle for you
  13. 50:27Gilectomy "Remove the GIL": replace unique GIL with one lock per mutable object • Atomic increment/decrement • Log INCREF/DECREF • Reference counting doesn't scale with the number of threads
  14. 52:27Tracing GC for CPython • Many modern language implementations use tracing GC . PyPy has a tracing GC • Existing C API would continue to use reference counting
  15. 53:29Eric Snow's PEP 554 "Multiple Interpreters in the Stdlib" • Replace the unique Global Interpreter Lock (GIL) with one lock per interpreter Work-in-progress refactoring of CPython complex internals
  16. 57:09Conclusion • Many previous optimizations projects failed Cython, multiprocessing and Numba are working well to make your code faster • HPy, tracing GC and subinterpreters are very promising!
~/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.