Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rkyv, avoid the copy to byte ? #2573

Closed
XavDesbordes opened this issue May 3, 2024 · 4 comments
Closed

rkyv, avoid the copy to byte ? #2573

XavDesbordes opened this issue May 3, 2024 · 4 comments

Comments

@XavDesbordes
Copy link

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
Copy link
Collaborator

gbj commented May 3, 2024

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
Copy link
Author

That will be my first PR but yes definitely!

@XavDesbordes
Copy link
Author

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
Copy link
Author

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

Please forget that (non) issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants