Reproduce “Rust vs. C for Python Libraries: Evaluating Rust-Compatible Bindings Toolchains” on OpenResearch

Turn your favorite coding agents into research agents that review literature, develop hypotheses, and run experiments.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Isabella Basso do Amaral, Renato Cordeiro Ferreira, Alfredo Goldman

Researchers at the University of São Paulo quantitatively compared Rust-compatible binding toolchains (PyO3) against traditional C-based methods (ctypes, cffi) for Python libraries, demonstrating that PyO3 achieves performance competitive with NumPy while offering a superior developer experience. The study found that minimizing per-call data conversions through specialized constructors is key to high performance, with PyO3 exhibiting lower per-call overheads than NumPy in certain tasks.

Key insights

  • Minimizing per-call data conversions by employing specialized constructors (M2 API design) is critical for achieving significant performance gains in hybrid-language Python libraries.
  • The Rust `PyO3` toolchain offers the most ergonomic and developer-friendly experience, abstracting FFI details and simplifying Python-native interface definitions through macros and seamless `Maturin` integration.
  • While highly optimized C-backed libraries like NumPy maintain an edge due to deep optimizations, well-designed Rust bindings can achieve comparable performance and even lower per-call overheads in specific computational scenarios.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.