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

Implementing get_size for everything #197

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

blockiosaurus
Copy link
Contributor

Fully implementing get_size and switching to that over serialized data size.

Copy link

vercel bot commented Nov 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mpl-core-js-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 30, 2024 10:04pm

@nhanphan
Copy link
Contributor

Is there a way to add a test to check the sizes are actually what we expect? (Eg they match with the plugin header)

@blockiosaurus
Copy link
Contributor Author

You're right. We should probably have serialization size tests for every plugin.

Copy link
Contributor

@danenbm danenbm left a comment

Choose a reason for hiding this comment

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

Looked at the trait implementations. Still need to look at processor code.

programs/mpl-core/src/plugins/lifecycle.rs Outdated Show resolved Hide resolved
@@ -88,6 +88,38 @@ impl Plugin {

impl Compressible for Plugin {}

impl DataBlob for Plugin {
fn get_initial_size() -> usize {
1
Copy link
Contributor

Choose a reason for hiding this comment

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

is this really 1 or since there's no None, is it each plugin's initial size?

1 + match self {
    Plugin::Royalties(royalties) => royalties.get_initial_size()
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's still one byte required for the plugin enum discriminator.

Copy link
Contributor

@danenbm danenbm Dec 19, 2024

Choose a reason for hiding this comment

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

Right but there's no default value that is only the descriminator, so there's no time you could ever use BASE_LEN and it would be correct, right?

Whereas for example Attribute, the BASE_LEN would be the length of an empty key/value pair and you could call it for a default value.

I can't think of a good solution for this except for adding a None variant, which is a contrived solution as there's not an actual reason to add it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah I see what you mean. Maybe BASE_LEN should be private or not required?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like that idea of not having BASE_LEN as a public trait const, and then people should only ever use len() which would work for empty or non-empty items. Like len() should always be trustable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a little annoying when we have multi-level data blobs, still. Because with no public BASE_LEN you need to hard code the underlying type's size.

programs/mpl-core/src/plugins/mod.rs Outdated Show resolved Hide resolved
programs/mpl-core/src/plugins/plugin_registry.rs Outdated Show resolved Hide resolved
programs/mpl-core/src/plugins/utils.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@danenbm danenbm 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 but I agree with both of you we should add that testing now.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 33b5220 Previous: 87e2e35 Ratio
CU: create a new, empty asset 11182 Compute Units 11082 Compute Units 1.01
Space: create a new, empty asset 91 Bytes 91 Bytes 1
CU: create a new, empty asset with empty collection 22655 Compute Units 22555 Compute Units 1.00
Space: create a new, empty asset with empty collection 91 Bytes 91 Bytes 1
CU: create a new asset with plugins 35091 Compute Units 40123 Compute Units 0.87
Space: create a new asset with plugins 194 Bytes 194 Bytes 1
CU: create a new asset with plugins and empty collection 41167 Compute Units 46145 Compute Units 0.89
Space: create a new asset with plugins and empty collection 194 Bytes 194 Bytes 1
CU: list an asset 28041 Compute Units 30237 Compute Units 0.93
CU: sell an asset 39312 Compute Units 38699 Compute Units 1.02
CU: list an asset with empty collection 35599 Compute Units 37795 Compute Units 0.94
CU: sell an asset with empty collection 51640 Compute Units 51027 Compute Units 1.01
CU: list an asset with collection royalties 36336 Compute Units 38499 Compute Units 0.94
CU: sell an asset with collection royalties 56565 Compute Units 55952 Compute Units 1.01
CU: transfer an empty asset 6420 Compute Units 6320 Compute Units 1.02
CU: transfer an empty asset with empty collection 9018 Compute Units 8918 Compute Units 1.01
CU: transfer an asset with plugins 14719 Compute Units 14604 Compute Units 1.01
CU: transfer an asset with plugins and empty collection 17317 Compute Units 17202 Compute Units 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@danenbm danenbm left a comment

Choose a reason for hiding this comment

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

Overall looks great and love the testing, but I have one nagging concern about BASE_LEN (see comments)

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.

3 participants