-
Notifications
You must be signed in to change notification settings - Fork 355
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
Key deserializer improvements #467
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of missed chances for optimisations.
Please just give a default trait implementation, and it is clear which ones you leave un-optimized.
I highlighted a number that could be optimised. (All String/Addr related stuff)
Add as_slice as default trait impl
Now it's better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Two last places that could be a bit more efficient, then happy to merge
packages/storage-plus/src/de.rs
Outdated
@@ -191,18 +139,13 @@ impl<T: KeyDeserialize, U: KeyDeserialize> KeyDeserialize for (T, U) { | |||
|
|||
Ok((T::from_slice(t)?, U::from_slice(u)?)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm.. could you use from_vec
here as well?
I guess you would need value.split_off rather than split_at
. But should be more consistent/efficient
packages/storage-plus/src/de.rs
Outdated
@@ -221,11 +164,6 @@ impl<T: KeyDeserialize, U: KeyDeserialize, V: KeyDeserialize> KeyDeserialize for | |||
|
|||
Ok((T::from_slice(t)?, U::from_slice(u)?, V::from_slice(v)?)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the (T, U) tuples (from_vec)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it. It's a little unclear with the var names. And, I doubt it's more efficient.
If we wanted a self-contained version (that is, one that doesn't depend on from_slice
), we could always use from_vec(t.to_vec())
and still work with slices / references in the mean time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, for triples, the version with split_off()
has four vec allocations instead of three; because of the small vec for the length of v
. Plus, it requieres a conversion to to_slice()
for calling try_into()
. Plus mut
vecs.
I really like the previous version better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
So, I guess you prefer the version with |
Why is it better? Easier to read code? |
OK then. |
Closes first part of #464.