Performance Regression in Rust Module with PyO3 in Python 3.13.2 #4942
Replies: 1 comment 4 replies
-
Important data points we'd need to know: what PyO3 version(s) are you using, what Rust compiler version, and are you using the freethreaded build of Python 3.13? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've recently developed a computational module in Rust using PyO3 and observed significant performance differences between Python 3.12.9 and 3.13.2. I'm sharing my findings to understand if others have experienced similar issues or if there's something wrong with my implementation.
Environment
Python 3.12.9: [GCC 14.2.0] (February 5, 2025)
Python 3.13.2: [GCC 14.2.0] (February 5, 2025)
Benchmarking Results
Python 3.12.9
rust multiply execution time: 0.000855 seconds
ecc_py multiply execution time: 0.001347 seconds
rust add execution time: 0.000415 seconds
ecc_py add execution time: 0.000520 seconds
Python 3.13.2
rust multiply execution time: 0.009020 seconds
ecc_py multiply execution time: 0.001272 seconds
rust add execution time: 0.001548 seconds
ecc_py add execution time: 0.000463 seconds
Observations
In Python 3.12.9, the Rust implementation is faster for both operations:
For multiplication: Rust is ~1.6x faster than the Python implementation
For addition: Rust is ~1.3x faster than the Python implementation
However, in Python 3.13.2, this advantage is completely lost:
For multiplication: Rust is ~7x slower than the Python implementation
For addition: Rust is ~3.3x slower than the Python implementation
This seems to indicate a significant regression in PyO3 performance with Python 3.13.2. Has anyone else encountered similar issues? Any suggestions for optimizing the Rust/PyO3 code for Python 3.13.2?
Beta Was this translation helpful? Give feedback.
All reactions