Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
Vectorize with NumPy or Polars when the work fits array or dataframe operations, compile hot functions with Cython or Numba, rewrite a small core in Rust via PyO3 or in C, or move the work to a separate service; choose by speedup, maintenance cost and team skills.
First confirm with profiling that the hot spot is truly CPU work in Python and not I/O or a better algorithm in disguise. Vectorized libraries run loops in optimized native code and often give large speedups with little new code. Numba compiles numeric Python functions with a decorator, while Cython adds C-level types for tight loops. Rust with PyO3 and maturin offers memory safety and easy packaging of wheels for a focused, stable core. Multiprocessing or the free-threaded build can add parallelism. Each option adds build complexity, platform-specific wheels and a narrower pool of maintainers, so keep the native part small, keep a Python reference implementation for tests, and benchmark the real workload.