Skip to content
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

Simplify registrar benchmarks #566

Merged
merged 10 commits into from
Jun 5, 2024
Merged

Conversation

tmpolaczyk
Copy link
Contributor

@tmpolaczyk tmpolaczyk commented Jun 3, 2024

Remove unused parameters from pallet_registrar benchmarks.

For instance, most extrinsics had a param "y: number of registered chains" that was always hardcoded to T::MaxLengthParaIds::get(). While making the benchmark parametric provides useful information about whether the weight depends on the number of chains or not, it also increases the time it takes to run benchmarks by a significant factor, so at the end it is not worth it.

Also add a script to automatically run benchmarks and update weights for the pallet and both runtimes, previously you had to copy the weights manually. I hope this will improve developer experience when dealing with benchmarks.

191, 27, 227, 32, 0, 0, 0, 0, 0, 0, 0, 0, 128, 254, 108, 203, 37, 75, 132, 240, 210, 32, 46,
181, 5, 189, 223, 159, 84, 203, 158, 189, 15, 178, 113, 144, 114, 233, 46, 229, 124, 29, 161,
216, 9,
0, 55, 133, 53, 79, 12, 10, 168, 38, 54, 66, 50, 252, 54, 227, 253, 113, 215, 29, 209, 8, 221,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has changed because previously I used let account = ALICE; below, but that doesn't work because of an invalid signature error when running:

cargo test -p pallet-registrar --features=runtime-benchmarks

I didn't notice before because this command is not being run in CI

@@ -64,20 +65,60 @@ mod benchmarks {
}
}

/// Creates a `ContainerChainGenesisData` with encoded size very near to `max_encoded_size`, and
/// with the provided number of keys.
fn max_size_genesis_data<T: Config>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is needed because setting the storage to T::MaxGenesisDataSize::get() results in an encoded size greater than that, because the encoded size also includes fields other than the storage, such as id, name, extensions, etc. That overhead was around 80 bytes if I remember correctly.

) -> Result<(), BenchmarkError> {
// This extrinsic is disabled in flashbox runtime, return 0 weight there
let _origin = T::RegisterWithRelayProofOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't use this origin below because the signature is only valid for the account created by create_funded_user below, but if this returns an error it means that the extrinsic cannot be called, so we return a weight of zero.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! then the benchmarks dont fail right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I have run them and there is a weight of 0 in flashbox, and non-zero in dancebox

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

@@ -375,7 +447,7 @@ mod benchmarks {
}

// Second loop to fill RegisteredParaIds to its maximum
for k in 1000..(1000 + y) {
for k in 1000..(1000 + y - 1) {
Copy link
Contributor Author

@tmpolaczyk tmpolaczyk Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This -1 is because if we fill RegisteredParaIds to its maximum, the call below will fail because the list is full, so we need to leave space for 1 chain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's good to add this as a comment in the code?

@tmpolaczyk tmpolaczyk added B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes breaking Needs to be mentioned in breaking changes D3-trivial PR contains trivial changes in a runtime directory that do not require an audit labels Jun 3, 2024
Copy link
Contributor

github-actions bot commented Jun 3, 2024

Coverage Report

(master)

@@                        Coverage Diff                        @@
##           master   tomasz-benchmarks-less-params      +/-   ##
=================================================================
+ Coverage   69.20%                          69.32%   +0.12%     
  Files         224                             224              
- Lines       39497                           39347     -150     
=================================================================
- Hits        27331                           27274      -57     
- Misses      12166                           12073      -93     
Files Changed Coverage
/pallets/registrar/src/weights.rs 24.17% (-0.83%) 🔽

Coverage generated Wed Jun 5 11:27:37 UTC 2024

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great script!

@tmpolaczyk tmpolaczyk merged commit 2fb1c08 into master Jun 5, 2024
32 checks passed
@tmpolaczyk tmpolaczyk deleted the tomasz-benchmarks-less-params branch June 5, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes breaking Needs to be mentioned in breaking changes D3-trivial PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants