leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
15.31k stars 599 forks source link

rkyv, avoid the copy to byte ? #2573

Closed XavDesbordes closed 2 months ago

XavDesbordes commented 2 months ago

Looking at the code, I think there is a copy that shoul dbe avoided in the following code:

There is the serialization, which is fine and gives an AlignedVec that is then re-encoded a Bytes. The annoyance comes from Bytes::copy_from_slice(encoded.as_ref());

Is there a way to send the AlignedVec directly ?

gbj commented 2 months ago

IIRC you can convert the rkyv type into a boxed slice, and then Bytes from a boxed slice, without copies.

Any interest in making a PR?

XavDesbordes commented 2 months ago

That will be my first PR but yes definitely!

XavDesbordes commented 2 months ago

Just dug into AlignedVec implementation, converting the AlignedVec into a Boxed slice via into_boxed_slice reallocates, "This method reallocates and copies the underlying bytes. Any excess capacity is dropped.".

I will try something else.

XavDesbordes commented 2 months ago

Apparently, it works directly with the AlignedVec. Don't know why it failed, before.

Please forget that (non) issue