-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Migrate existing benchmarks!
macro to attribute macros
#10848
Comments
For the record, i created this issue by "half accident". Nevertheless, it still needs to be done. So, someone who will work on this, should update the description properly. |
@shawntabrizi I added some context to the issue. I think if we use something like |
benchmarks!
macro to attribute macrosbenchmarks!
macro to attribute macros
So I've been working through the existing benchmarking macro code and I really like the syntax you propose @bkchr That said, I'm curious what your thoughts are on detecting/annotating the components setup, the extrinsic call, and the post conditions verification code. My understanding based on how the underlying traits and structs work is we do need to be able to separate these out in our macro, but maybe I'm wrong about that. If I'm wrong, then we could totally do your suggested syntax for this without modification, and I'd be totally for that. I'm going to play around a bit more with cargo expand today to get a definitive answer. If I am right and we do need some way of identifying these separate regions of the code, I wonder if we could just annotate the extrinsic call and use this as a bisection/divider between the components setup and the post-condition verification code, something like this: #[pallet::benchmark]
fn bench_name(x: LinearComponent<0, MAX_X>, y: LinearComponent<0, MAX_Y>) {
// Setup code
let z = x + y;
let caller = whitelisted_caller();
// The extrinsic call.
#[extrinsic_call]
extrinsic_name(z, other_arguments...);
// Post condition verification
assert_eq!(MyPallet::<T>::my_var(), == z);
} Then we can eat that Thoughts on this? Is this totally unnecessary? |
Hey @sam0x17, the suggested code was actually from me 😄 High level we want to get closer to the standard Rust syntax as from what we currently have - entirely custom syntax. The idea about the @shawntabrizi probably has some more ideas about it. |
@ggwpez looks like my reply I had typed out the other day didn't post That is good to hear. I have been working on parsing code for the above syntax with my #[extrinsic_call] annotation as laid out above. Planning to try to generate the original inner structs and trait impls from there so we can make this minimally invasive. |
@ggwpez what is the deal with the whole |
Hi @sam0x17, |
So I opted for making a trait called |
Currently benchmarks are written in the following form:
A better way of writing them would be closer to how tests are written in rust:
The text was updated successfully, but these errors were encountered: