-
Notifications
You must be signed in to change notification settings - Fork 29
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
perf: Add into_bytes
to Storable
to avoid cloning where possible
#249
Conversation
The same idea may apply to Edit: No, it doesn't apply there because the bytes are never converted to a |
I'm really not sure about the |
Also, using |
|
Woah I didn't get those canbench regressions when running locally! |
I think it's probably not worth merging this.
But all other benchmarks remain almost exactly the same. |
FYI, there's this old issue which is also related. Indeed, with generic specializations we could implement |
In OpenChat I have just introduced a
StableBTreeMap
where the values areVec<u8>
.I saw that when calling
map.insert(..)
the bytes were being cloned becauseStorable::to_bytes
take a reference toself
so forVec<u8>
the response isCow::Borrowed(self)
, then when callinginto_owned
the bytes are cloned.This PR adds an optional
into_bytes
method to theStorable
trait which by default simply calls intoto_bytes
.Implementing
into_bytes
allows for values to be inserted with cloning the bytes.The downside is that I've had to add the
Sized
trait toStorable
which is a breaking change and may not be desired.