Skip to content

Commit

Permalink
Add docs for dev-benchmark-pallet.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Feb 11, 2025
1 parent 03c4fe8 commit d476aa2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions docs/benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,39 @@ TEMPLATE_PATH=benchmarking/frame-weight-pallet-template.hbs OUTPUT_PATH=pallets/
```
BINARY=target/release/container-chain-simple-node TEMPLATE_PATH=benchmarking/frame-weight-pallet-template.hbs OUTPUT_PATH=../dancekit/container-chain-pallets/authorities-noting/src/weights.rs ./tools/benchmarking.sh "pallet_cc_authorities_noting" "*"
```


# Faster local development

There is a script `tools/dev-benchmark-pallet.sh` that aims to improve developer experience
related to per-runtime weights.

## Adding new extrinsics

When we add a new extrinsic to one of our pallets, we also need to add a benchmark.
But that will make all the runtimes that include that pallet fail to compile, because the
per-runtime weights do not include that new extrinsic.

The usual solution is to add a dummy weight for the new extrinsic in each runtime, and then
run the benchmarks again to check that the number of storage reads/writes is reasonable.

The dummy weights need to be added manually, but there is a helper script for updating the
weights with the actual value.

Usage:

```
cargo build --release --features=fast-runtime,runtime-benchmarks
git commit -am 'before running benchmarks"
./tools/dev-benchmark-pallet.sh "pallet_registrar"
```

This automatically copies the weights to the expected location for each runtime, and it runs the benchmarks locally with `--check=1`, so very few iterations.

This script can also be used when the benchmark for an existing extrinsic changes, by taking a new parameter or if there are changes to the algorithm and now it takes a different amount of storage reads.

## Adding new pallets

This script can also be used to simplify the flow of adding new pallets.
For that you need to run it with `FORCE_COPY=1` env variable, because by default it will only
update the weight files for runtimes that already include that pallet.
2 changes: 1 addition & 1 deletion tools/dev-benchmark-pallet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# the expected location.
#
# Usage:
# cargo build --release --features=runtime-benchmarks
# cargo build --release --features=fast-runtime,runtime-benchmarks
# git commit -am 'before running benchmarks"
# ./tools/dev-benchmark-pallet.sh "pallet_registrar"
#
Expand Down

0 comments on commit d476aa2

Please sign in to comment.