-
Notifications
You must be signed in to change notification settings - Fork 711
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
Idea: Reflections for WeightInfo
functions
#382
Comments
I'm interested in picking this up, but not sure I quite get the proposal. From my understanding, something like this is what's being asked for:
Or a struct containing a hashmap |
One way could refactor out all the code generation logic. Instead of generate codes that hard to be consumed by other tools, it should generate data. e.g. trait GetWeightInfoData {
fn weight_data(call: Call) -> WeightInfoData;
fn weight<const S: usize>(call: Call, args: [u32: S]) -> Weight {
// do the math
}
}
struct WeightData {
weight: Weight,
reads: u64,
writes: u64,
}
struct WeightInfoData {
base: WeightData,
args: Vec<WeightData>,
}
enum Call {
AddRegistrar,
SetIdentity,
}
impl GetWeightInfoData for Call {
fn weight_data(call: Call) -> WeightInfoData {
match call {
Call::AddRegistrar => WeightInfoData {
base: WeightData {
weight: Weight::from_ref_time(16_649_000 as u64),
reads: 1,
writes: 1,
},
args: vec![
WeightData {
weight: Weight::from_ref_time(241_000 as u64),
reads: 0,
writes: 0,
}
],
}
Call::SetIdentity => WeightInfoData {
base: WeightData {
weight: Weight::from_ref_time(31_322_000 as u64),
reads: 1,
writes: 1,
},
args: vec![
WeightData {
weight: Weight::from_ref_time(252_000 as u64),
reads: 0,
writes: 0,
},
WeightData {
weight: Weight::from_ref_time(312_000 as u64),
reads: 0,
writes: 0,
}
],
}
}
}
} In that way it is easy to work with |
Thanks for the ideas @xlc. Using data here instead of math terms should make it easier downstream indeed. |
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
* Change script to update versions. * Bump versions. * Address remainders. * cargo fmt --all * Fix tests. * Whitelist BlueOak license * Fix benchmarks?
Currently we have the
WeightInfo
trait which exposes several weight functions in the form of:Sometimes you want to iterate over all weight functions and do something weight their name or result (eg in paritytech/substrate#12485).
One way to do this would be to have another type;
WeightMetaInfo
whose implementation is auto-generated as well:This would allow us to do:
WeigtInfo
implementations such that the weight of a call can be dynamically set in a test (Is already possible, but not in a spell-checked way without ugly macros).Zero
or straytodo!()
).I am not entirely convinced that this is the best design, but having this in some way would be nice.
The text was updated successfully, but these errors were encountered: