-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
pyo3 large memory footprint when making lists #872
Comments
And if you need a 'quick remedy' for this, I recommend using rust-numpy. Numpy array is much more efficient than list. |
Thanks, rust-numpy reduced the memory footprint substantially. |
I just revisited, bumping the sample Amazingly everything compiled without changes. Also it looks like whatever the original issue was, it's been resolved. Here's the profile I got this morning: The Rust peak is now actually lower than the pure-Python peak! 👀 |
🐛 Bug Reports
Not entirely sure if bug or working as intended, but lists created from returned pyo3 calls appear to have nearly twice the memory footprint as native python versions, even though the underlying rust representation of the lists can be trivial by comparison. I ran into this issue when running into out of memory issues which I had not expected.
I have been testing the memory usage using memory-profiler from PyPi. I will try others, but the high memory usage seems to agree with some out of memory issues I was experiencing in other places, so I'm confident in the output. See here for the repo with the testing code.
I tested two situations:
py_function returning a list of 100,000,000 bools, this is ~ 20MB in rust, and nearly a GB in python, but pyo3 uses about 1750MB to create the list, after creation memory returns to normal.
py_function returns nested list of tuples with lists inside, also a total of 100,000,000 bools (+16 floats). This again uses only a few MB in rust, nearly a GB in python, but the rust produced version never moves past its peak memory usage and stays at 1750MB until the object is deleted. This doesn't appear to be a memory leak since it is removed with the object, so I'm not sure it fits with #311 / #793. Although this may be fixed with #679 if there isn't another issue.
🌍 Environment
rustc --version
): 1.44.0-nightlyversion = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
I've been using 0.9.2, using git has no effect on results.💥 Reproducing
Here is a repo with the code I used to test these claims.
Final Note
This is a great project, I use it every day for physics research + simulation!
The text was updated successfully, but these errors were encountered: