Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

benches: disable caching per default #12232

Merged
merged 4 commits into from
Sep 13, 2022

Conversation

ggwpez
Copy link
Member

@ggwpez ggwpez commented Sep 9, 2022

Spotted some large weight decrease for BlockExecutionWeight on the Polkadot release branch v0.9.29 here.
It comes from the new Trie cache #11407 feature which has unforeseen influence on the weights here.

This MR disables caching per default and makes enabling it explicit.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez ggwpez added A0-please_review Pull request needs code review. B5-clientnoteworthy C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Sep 9, 2022
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

After thinking about this more. I'm not sure how it worked before?

And when we disable the cache, wouldn't this hurt the other benchmarks which rely on the cache working?

@@ -105,7 +105,7 @@ pub struct StorageParams {
/// Trie cache size in bytes.
///
/// Providing `0` will disable the cache.
#[clap(long, default_value = "1024")]
#[clap(long, default_value = "0")]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[clap(long, default_value = "0")]
#[clap(long, default_value = "1024")]

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise it would not get enabled when you set enable_trie_cache.

Copy link
Member Author

@ggwpez ggwpez Sep 12, 2022

Choose a reason for hiding this comment

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

After thinking about this more. I'm not sure how it worked before?

I am not sure either. Maybe the state-cache just did not have such a large influence as the Trie cache now does.
But yea, the former results should already be wrong due to state-caching. I did not notice this earlier, as --state-cache-size did not make a noticeable difference.

And when we disable the cache, wouldn't this hurt the other benchmarks which rely on the cache working?

Well, we need to measure worst case performance… so a second iteration of a benchmark should not rely on a former iteration. None of the benches should actually rely on a cache.

Otherwise it would not get enabled when you set enable_trie_cache.

I did not put a --enable-trie-cache for the storage command, since the trie-cache-size was not inherited from the import commands. But I will add it for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait I think this is bytes, will change to 67108864.

Copy link
Member

Choose a reason for hiding this comment

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

Well, we need to measure worst case performance… so a second iteration of a benchmark should not rely on a former iteration. None of the benches should actually rely on a cache.

Makes sense, but how do we then handle values which we assume of already being present? Aka the whitelisted values? Do we just somehow remove them from the formular that gives us the weight?

Copy link
Member Author

@ggwpez ggwpez Sep 12, 2022

Choose a reason for hiding this comment

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

Do we just somehow remove them from the formular that gives us the weight?

For pallet weights: Yes.

fn read_write_count(&self) -> (u32, u32, u32, u32) {
let mut reads = 0;
let mut repeat_reads = 0;
let mut writes = 0;
let mut repeat_writes = 0;
self.all_trackers().iter().for_each(|tracker| {
if !tracker.whitelisted {

That could be written a bit nicer with a .filter 🙈

For storage weights: Does not matter, since we need the average read/write weight for a key, regardless of whitelist, since whitelisted values are also read once.
For BlockExecutionWeight and ExtrinsicBaseWeight: No, since this is where we want to account for the cost of whitelisted keys, so they are included here.

ggwpez and others added 2 commits September 12, 2022 12:09
Co-authored-by: Bastian Köcher <info@kchr.de>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez
Copy link
Member Author

ggwpez commented Sep 13, 2022

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 9df9448 into master Sep 13, 2022
@paritytech-processbot paritytech-processbot bot deleted the oty-fix-bench-caching branch September 13, 2022 11:32
altonen pushed a commit that referenced this pull request Sep 14, 2022
* Disable cache for storage benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Disable caching per default

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update utils/frame/benchmarking-cli/src/storage/cmd.rs

Co-authored-by: Bastian Köcher <info@kchr.de>

* Add --enable-trie-cache to 'storage' command

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <info@kchr.de>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Disable cache for storage benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Disable caching per default

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update utils/frame/benchmarking-cli/src/storage/cmd.rs

Co-authored-by: Bastian Köcher <info@kchr.de>

* Add --enable-trie-cache to 'storage' command

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <info@kchr.de>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
Development

Successfully merging this pull request may close these issues.

3 participants