-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Is there a way to add a test to check the sizes are actually what we expect? (Eg they match with the plugin header) |
You're right. We should probably have serialization size tests for every plugin. |
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.
Looked at the trait implementations. Still need to look at processor code.
4 + self | ||
.attribute_list | ||
.iter() | ||
.fold(0, |acc, attr| acc + attr.get_size()) |
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.
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>()
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.
Nice! That's much better and same in CUs.
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 |
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.
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 |
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.
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() |
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.
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::{ |
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.
Nit: I thought in another PR you switched all the super
to crate
?
programs/mpl-core/src/plugins/mod.rs
Outdated
@@ -88,6 +88,38 @@ impl Plugin { | |||
|
|||
impl Compressible for Plugin {} | |||
|
|||
impl DataBlob for Plugin { | |||
fn get_initial_size() -> usize { | |||
1 |
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.
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()
...
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.
There's still one byte required for the plugin enum discriminator.
programs/mpl-core/src/plugins/mod.rs
Outdated
impl From<PluginType> for usize { | ||
fn from(plugin_type: PluginType) -> Self { | ||
plugin_type as usize | ||
} | ||
} |
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.
Don't we normally do this with #[derive(ToPrimitive)]
2 + 1 + 8 | ||
} | ||
|
||
fn get_size(&self) -> usize { | ||
2 + self.authority.get_size() + 8 |
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.
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?
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.
Yup you're right.
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(); |
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.
Nice!
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 but I agree with both of you we should add that testing now.
…dation/mpl-core into feat/impl-get-size
This reverts commit 84758e9.
…foundation/mpl-core into feat/impl-get-size
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.
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.
…into feat/impl-get-size
Fully implementing get_size and switching to that over serialized data size.