Python performance Past, Present, Future
summary
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
chapters (16)
- 0:00Intro
- 1:12Python Implementations • 1989: CPython (Guido van Rossum) • 1997: Jython (Jim Hugunin) • 1998: Stackless Python Christian
- 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?
- 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
- 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?
- 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
- 23:59CPython: multiprocessing Process Thread Maths (CPU bound) Process
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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!
related talks
48mPython Performance: Past, Present and Future
57mPython and PyPy performance (not) for dummies
22mPyPy and the future of the Python ecosystem
22mPyPy in production
26mWhy are Python and Ruby slow?
22mPyPy hands-on
01h 00mKeynote: Python now and in the future
26mThe Future of Python: Evolution or Succession?
