uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

`bytes`/`string`s can be passed more efficiently

Open heinrich5991 opened this issue 2 years ago • 5 comments

E.g. passing bytes from Python to Rust involves two copies, when it could be zero copies if the Rust code accepted &[u8]. The other way around currently involves two copies as well, which could be reduced to one (the creation of the Python bytes).

┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-281

heinrich5991 avatar Jun 05 '23 19:06 heinrich5991

Its not just about copies. Currently Rust bytes implementation uses for loop to copy individual bytes from RustBuffer into Vec<u8>. memcpy would be far more efficient.

arg0d avatar Nov 15 '23 15:11 arg0d

Do you think using memcpy instead of for loop is a separate issue or not?

arg0d avatar Nov 15 '23 15:11 arg0d

This issue title is broad enough I think it's fine to cover both cases. If it turns out a patch is submitted which only solves some inefficiencies but leaves others on the table, then it makes sense for a new more-specific issue to exist at that point.

mhammond avatar Nov 15 '23 15:11 mhammond

Its not just about copies. Currently Rust bytes implementation uses for loop to copy individual bytes from RustBuffer into Vec<u8>. memcpy would be far more efficient.

Have you verified that it's not actually optimized into a memcpy already?

heinrich5991 avatar Nov 15 '23 16:11 heinrich5991

Good point, I didn't check that.

arg0d avatar Nov 15 '23 16:11 arg0d