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

Key deserializer improvements #467

Merged
merged 7 commits into from
Oct 4, 2021
Merged

Conversation

maurolacy
Copy link
Contributor

Closes first part of #464.

@maurolacy maurolacy self-assigned this Oct 4, 2021
Copy link
Member

@ethanfrey ethanfrey left a 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)

packages/storage-plus/src/de.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/de.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/de.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/de.rs Outdated Show resolved Hide resolved
Add as_slice as default trait impl
@maurolacy
Copy link
Contributor Author

Now it's better.

Copy link
Member

@ethanfrey ethanfrey left a 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 Show resolved Hide resolved
@@ -191,18 +139,13 @@ impl<T: KeyDeserialize, U: KeyDeserialize> KeyDeserialize for (T, U) {

Ok((T::from_slice(t)?, U::from_slice(u)?))
Copy link
Member

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

@@ -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)?))
Copy link
Member

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)

Copy link
Contributor Author

@maurolacy maurolacy Oct 4, 2021

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.

Copy link
Contributor Author

@maurolacy maurolacy Oct 4, 2021

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.

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

@maurolacy
Copy link
Contributor Author

maurolacy commented Oct 4, 2021

So, I guess you prefer the version with split_off then? The version with split_at is better IMO.

@ethanfrey
Copy link
Member

ethanfrey commented Oct 4, 2021

The version with split_at is better IMO.

Why is it better? Easier to read code?
Split off should be more efficient (and this is internal code no one should look at)

@maurolacy
Copy link
Contributor Author

OK then.

@maurolacy maurolacy merged commit 7344c12 into main Oct 4, 2021
@maurolacy maurolacy deleted the 464-key_deserializer-improvements branch October 4, 2021 18:20
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

Successfully merging this pull request may close these issues.

2 participants