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 13 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 10, 2024 3:50pm

@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.

Comment on lines 45 to 48
4 + self
.attribute_list
.iter()
.fold(0, |acc, attr| acc + attr.get_size())
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This is elegant but I think using map and sum could be more simple, i.e.:

        self
        .attribute_list
        .map(|attr| attr.get_size())
        .sum::<usize>()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! That's much better and same in CUs.

Comment on lines +36 to +38
ProgramAllowList(Vec<Pubkey>), // 4
/// Deny list of programs that are not allowed to transfer, receive, or send the asset.
ProgramDenyList(Vec<Pubkey>),
ProgramDenyList(Vec<Pubkey>), // 4
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: consistency, sometimes the commented length is the initial/default length of zero, other times it is listed as like 4 + len * Object


impl DataBlob for Royalties {
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.

Shouldn't this be 7, or 2 + 4 + RuleSet::get_initial_size()?

}

fn get_size(&self) -> usize {
4 + self.signatures.len() * VerifiedCreatorsSignature::get_initial_size()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It happens to be fine since its fixed size but I think technically better to use get_size() here rhather than get_initial_size().

@@ -8,7 +8,7 @@ use crate::{
state::{Authority, Key, UpdateAuthority},
};

use crate::plugins::{
use super::{
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I thought in another PR you switched all the super to crate?

@@ -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.

Comment on lines 234 to 238
impl From<PluginType> for usize {
fn from(plugin_type: PluginType) -> Self {
plugin_type as usize
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we normally do this with #[derive(ToPrimitive)]

Comment on lines 151 to 155
2 + 1 + 8
}

fn get_size(&self) -> usize {
2 + self.authority.get_size() + 8
Copy link
Contributor

Choose a reason for hiding this comment

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

PluginType should be 1? But actually isn't it better to use PluginType::get_initial_size() and get_size()?

Even for Authority could use self.authority.get_initial_size() as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup you're right.

Comment on lines 267 to 270
let core = T::load(account, 0)?;
let header_offset = core.get_size();
let plugin_type = plugin.into();
let plugin_data = plugin.try_to_vec()?;
let plugin_size = plugin_data.len();
let plugin_size = plugin.get_size();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

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: 15b9054 Previous: 729fde8 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 35057 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 41079 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 28009 Compute Units 30237 Compute Units 0.93
CU: sell an asset 39437 Compute Units 38824 Compute Units 1.02
CU: list an asset with empty collection 35567 Compute Units 37795 Compute Units 0.94
CU: sell an asset with empty collection 51765 Compute Units 51152 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 56690 Compute Units 56077 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.

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