You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
We get storage_per_prefix data as the result, which originally was used for creating comments with information about the storage keys touched during each benchmark.
The Bug
In PR#11637 this data started to be used for calculation of the resulting proof_size formula into the weights.rs . But in a wrong way:
Step 1, (almost right). We find average base proof_size value and slope for each component, by making regression analysis of benchmark results we put to this component in storage_per_prefix (see above).
let proof_size_per_components = storage_per_prefix
.iter()
.map(|(prefix, results)| {
let proof_size = analysis_function(results,BenchmarkSelector::ProofSize)
.expect("analysis function should return proof sizes for valid inputs");
(This is almost right but not totally right, because the values we're making regression analysis on are not per-key benchmark results but originated from benchmark results for the all the keys and then adjusted for a single key, see below for details)
Step 2, (wrong). The resulting base_calculated_proof_size and component_calculated_proof_size values are calculated as a simple sum of the values for all prefixes from the per_prefix benchmark results.
for used_component in used_calculated_proof_size.iter_mut(){
if used_component.name == component.name{
used_component.slope += component.slope;
But, wait a minute. To recap, the path of these proof_sizes is:
They first were calculated for all keys in each benchmark run.
Then we multiplied them for each key, adjusted depending on reads overhead for the key. (which is weird because we're adding up overhead of a single key PoV to proof_size of all the keys)
Then we summed up those multiplied values.
And this is wrong. It leads to exaggerated weights when being put to weights.rs:
Instead of a simple sum, those base_calculated_proof_size and component_calculated_proof_size should be calculated as averages or medians from all keys.
The text was updated successfully, but these errors were encountered:
Context
Results of benchmarks are processed with
writer::process_storage_results()
in the following way.It loops through all the storage keys of all results
substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs
Lines 549 to 550 in 9c92e49
and multiples each benchmark result for each key, adjusting the result's proof_size for each key, as it depends on:
substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs
Lines 628 to 632 in 9c92e49
We get storage_per_prefix data as the result, which originally was used for creating comments with information about the storage keys touched during each benchmark.
The Bug
In PR#11637 this data started to be used for calculation of the resulting proof_size formula into the
weights.rs
. But in a wrong way:Step 1, (almost right). We find average base proof_size value and slope for each component, by making regression analysis of benchmark results we put to this component in storage_per_prefix (see above).
substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs
Lines 299 to 303 in 9c92e49
(This is almost right but not totally right, because the values we're making regression analysis on are not per-key benchmark results but originated from benchmark results for the all the keys and then adjusted for a single key, see below for details)
Step 2, (wrong). The resulting base_calculated_proof_size and component_calculated_proof_size values are calculated as a simple sum of the values for all prefixes from the per_prefix benchmark results.
substrate/utils/frame/benchmarking-cli/src/pallet/writer.rs
Lines 317 to 323 in 9c92e49
But, wait a minute. To recap, the path of these proof_sizes is:
(which is weird because we're adding up overhead of a single key PoV to proof_size of all the keys)
And this is wrong. It leads to exaggerated weights when being put to
weights.rs
:substrate/.maintain/frame-weight-template.hbs
Lines 73 to 75 in 9c92e49
Suggested Fix
Instead of a simple sum, those base_calculated_proof_size and component_calculated_proof_size should be calculated as averages or medians from all keys.
The text was updated successfully, but these errors were encountered: