[WIP] Efficient movement of Vec<u8> to PyBytes#1427
[WIP] Efficient movement of Vec<u8> to PyBytes#1427milesgranger wants to merge 1 commit intoPyO3:masterfrom
Conversation
|
The fact that This is definitely not safe to use with the However, this (overallocating and then truncating) sounds more like a task for |
|
Thanks for the pointers! 👍 |
|
I was going to file an issue requesting a higher-level API utilizing While I agree I could certainly call the Python C APIs directly. But I was hoping there would be room in PyO3 to support some (possibly |
|
@indygreg we actually once considered an extension to the You could potentially roll something yourself which does that - or add it as a PR to pyo3. There's a long discussion in that thread why we decided not to do it at the time. In addition, we could support |
Hi!
This is related to #1385
I have a de/compression lib which gets some bytes in from Python, then passes them back.
Really like how
PyBytes::new_withworks; unfortunately, I don't know the exact size of the slice I want until after the de/compression operation. Using this approach, I end up with trailing null bytes.Using the standard
PyBytes::newfrom a slice, ends up making the new allocation and thus just puts the lib slower than the existing Python/C options. However, the approach above can be reliably 1.5x - 2x faster; so really pulling that something like this is possible. 🤞As you see in the PR, I naively attempted to use
ffi::_PyBytes_Resizebut it seems to have no effect?Thanks for the help!
(related to benchmarks: milesgranger/cramjam#12 (comment))