0

I have the following benchmark that takes a very long time to complete. What measures can I take to improve the time it takes to run the benchmark without losing its effectiveness?

on_initialize {
        let m in 1 .. 3_000;
        for j in 0 .. m {
            let mortality_block = 49 as u32;
            let sig = generate_test_signature();
            assert_ok!(Msa::<T>::register_signature(&sig, T::BlockNumber::from(mortality_block)));
        }

        let bucket_zero_iter = PayloadSignatureRegistry::<T>::iter_prefix(T::BlockNumber::from(0u32));
        assert_eq!(bucket_zero_iter.count(), m as usize);
    }: {
        Msa::<T>::on_initialize(100u32.into());
    } verify {
        let bucket_zero_iter = PayloadSignatureRegistry::<T>::iter_prefix(T::BlockNumber::from(0u32));
        assert_eq!(bucket_zero_iter.count(), 0 as usize);
    }

Running with the following configurations:

  • --steps 50
  • --repeat 10
3
  • 1
    I think the only way is low down the steps and repeat. Maybe I'm wrong.
    – aurexav
    Commented Dec 10, 2022 at 7:10
  • What is slow about it? Generating the signatures? Commented Dec 10, 2022 at 14:37
  • Good point. I am going to dive a litter deeper.
    – Yatusabes
    Commented Dec 12, 2022 at 17:38

1 Answer 1

4

I checked your code and the signature generation is very slow.
However, the signatures are never verified so you can get away by mocking them which is million times faster.
First lets increase the 3_000 to 50_000 for a larger effect. Then get rid of the generate_test_signature function and mock the signature.

let m in 1 .. 50_000;
for j in 0 .. m {
    let mut sig = [0u8; 64];
    sig[0..8].copy_from_slice(&(m, j).encode());
    let sig = MultiSignature::Sr25519(sp_core::sr25519::Signature::from_raw(sig));

    let mortality_block = 49 as u32;
    assert_ok!(Msa::<T>::register_signature(&sig, T::BlockNumber::from(mortality_block)));
}

PS: Running the benchmark tests with --release also helps.

Please always include source code links to your questions and an elaborate explanation of the problem, thanks.

Your Answer

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

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