2

I am trying to migrate my pallet over to the parachain template, and while adding it to the runtime I noticed a slight difference between how benchmarks are defined.

On the old runtime, all (or most) pallets had their benchmarks included as follows:

    impl frame_benchmarking::Benchmark<Block> for Runtime {
        fn dispatch_benchmark(
            // <snip>
            add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
            add_benchmark!(params, batches, pallet_balances, Balances);
            add_benchmark!(params, batches, pallet_timestamp, Timestamp);
            // Custom benchmark I want to migrate
            add_benchmark!(params, batches, pallet_chocolate, ChocolateModule);
            // <snip>

While the new one only has one call to a add_benchmarks macro.

    impl frame_benchmarking::Benchmark<Block> for Runtime {
        fn dispatch_benchmark(
            // <snip>
            add_benchmarks!(params, batches);
            // <snip>

I checked the docs and it suggests using the add_benchmark! but that was in the context of the node template. What's the difference between these two forms? Does add_benchmarks! have the same effect as the individual add_benchmark! calls combined??

Do note that I'm migrating from the node template runtime to the parachain template.

Many thanks!

1 Answer 1

2

Take a look at the PR which introduces this change:

https://github.com/paritytech/substrate/pull/10592

So the new syntax which is easier to maintain is:

define_benchmarks!(
    [path1, location1]
    ...
    [pathN, locationN]
);

impl_runtime_apis! {
    impl Benchmark<Block> for Runtime {
        fn benchmark_metadata(…)  {
            add_benchmarks!(list, extra);
        }

        fn dispatch_benchmark(…)  {
            list_benchmarks!(params, batches);
        }
    }
}

Where the define_benchmarks is combined with list_benchmarks and add_benchmarks.

This allows us to avoid having to have a huge list copied twice :)

End of the day, both syntax is supported, so you need not worry if you don't want to update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.