mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 17:58:27 +03:00
7831e2a4ce
Summary: I need to convert `Vec<u8>` to a Python object in a zero-copy way for rustlz4 performacne. Assuming Python and Rust use the same memory allocator, it's possible to transfer the control of a malloc-ed pointer from Rust to Python. Use this to implement zero-copy. PyByteArrayObject is chosen because its struct contains such a pointer. PyBytes cannot be used as it embeds the bytes, without using a pointer. Sadly there are no CPython APIs to do this job. So we have to write to the raw structures. That means the code will crash if python is replaced by python-debug (due to Python object header change). However, that seems less an issue given the performance wins. If python-debug does become a problem, we can try vendoring libpython directly. I didn't implement a feature-rich `PyByteArray` Rust object. It's not easy to do so outside the cpython crate. Most helper macros to declare types cannot be reused, because they refer to `::python`, which is not available in the current crate. Reviewed By: DurhamG Differential Revision: D13516209 fbshipit-source-id: 9aa089b309beb71d4d21f6c63fcb97dbc798b5f8 |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |