Making Python 100x faster with less than 100 lines of Rust
summary
Claims a ~100x speedup on a small numpy-based library by profiling with py-spy sampling profiler, porting the hottest Python function to Rust with pyo3 and maturin, then converting the Polygon class to a native Rust struct to avoid Python-level iteration and copies. Benchmarks drop from ~2880 ms per run to ~30 ms after two staged changes (first function replacement ~10x, then class-level rewrite ~10x), keeping the same API and under 100 lines of Rust.
AI-written summary · about
chapters (6)
- 0:00Introduction and context
- 3:19Identifying performance bottlenecks
- 7:56Profiling with py-spy
- 10:03Rewriting Python to Rust
- 14:02Benchmarking improvements
- 17:37Summary and results
related talks
36mPumping up Python modules using Rust
31mPumping up Python modules using Rust
31mCan Rust make Python shine?
34mRust for the Python dev
25mIntegrating Rust with Python...
42mIntuition vs. Reality: Surprising Truths in Python Performance
36mPolishing Python: Preventing Performance Corrosion with Rust
44mDo Pythons Rust? How we used PyO3 to build a Python Stream Processor w/ a Rust Heart
