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

Add PoV size to benchmark overhead #12378

Closed
wants to merge 17 commits into from
Closed

Add PoV size to benchmark overhead #12378

wants to merge 17 commits into from

Conversation

ggwpez
Copy link
Member

@ggwpez ggwpez commented Sep 28, 2022

Closes paritytech/polkadot-sdk#384

Adds the Storage proof size to the the overhead weight template.
New rendered extrinsic_weights.rs looks like this:

/// Time to execute a NO-OP extrinsic. For example `System::remark`.
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
...
pub const ExtrinsicBaseRefTime: u64 = WEIGHT_PER_NANOS.ref_time().saturating_mul(97_610);

/// Weight to execute a NO-OP extrinsic. For example `System::remark`.
pub const ExtrinsicBaseWeight: Weight = Weight::from_components(
	ExtrinsicBaseRefTime::get(),
	// There is no proof size consumed by a NO-OP extrinsic.
	0,
);

... and block_weights.rs:

/// Time to execute an empty block.
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
...
pub const BlockExecutionRefTime: u64 = WEIGHT_PER_NANOS.ref_time().saturating_mul(342_097);

/// Storage proof size to prove the execution of an empty block.
///
/// THIS IS NOT THE POV SIZE. The PoV size additionally includes the block size.
///
/// Compaction would result in `3_473` byte.
/// Compaction and compression would result in `3_163` byte.
pub const EmptyBlockProofSize: u64 = 4_857;

/// Storage proof size to prove the execution of a block with at least one extrinsic.
///
/// THIS IS NOT THE POV SIZE. The PoV size additionally includes the block size.
///
/// Compaction would result in `3_879` byte.
/// Compaction and compression would result in `3_365` byte.
pub const NonEmptyBlockProofSize: u64 = 5_422;

/// Weight to execute an empty block.
///
/// We do not distinguish between the weight of empty or non-empty blocks and
/// therefore use the assumed larger one, being non-empty.
pub const BlockExecutionWeight: Weight = Weight::from_components(
	BlockExecutionRefTime::get(),
	NonEmptyBlockProofSize::get(),
);

Further changes:

  • Handle overflow in calc_ref_time
  • Tests the rendered template output files
  • Remove the {{header}} HBS variable as it introduces an empty newline at the top of the rendered file when there is no header. Any header will be prepended directly.
  • Use the direct header to execute a block. Formerly it would assume genesis.

Open points

  • I added a test that applies rustfmt to a rendered template and checks that it would not modify it. I am fine with not merging it if that is too hacky.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez ggwpez added the A3-in_progress Pull request is in progress. No review needed at this stage. label Sep 28, 2022
@github-actions github-actions bot added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Sep 28, 2022
Copy link
Member

@shawntabrizi shawntabrizi left a comment

Choose a reason for hiding this comment

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

Looks like a good starting point. Please add an issue to follow up on some things here.

Perhaps a TODO on top of the zstd to perhaps have the API support generating a compressed proof, so we dont assume how compression happens here?

@shawntabrizi
Copy link
Member

👉 Question is how do we now get the base proof size of an extrinsic?

I don't think an extrinsic has a base storage proof size. So to calculate the impact to PoV (storage proof + block size) we add:

  1. the length of an extrinsic
  2. any storage it reads during execution

By default, (2) can be zero, and (1) can be as small as 2 bytes and a signature.

@ggwpez ggwpez added B0-silent Changes should not be mentioned in any release notes 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 A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Sep 28, 2022
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
/// Median: 5_328_139
/// Std-Dev: 41749.5
/// Statistics in nanoseconds:
/// Min, Max: 337_266, 439_477
Copy link
Member Author

@ggwpez ggwpez Oct 11, 2022

Choose a reason for hiding this comment

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

Somehow the block weights reduced a lot. This is also on master. It was fixed in Polkadot by this #12232 but not here?!

PS: I dienered Polkadot and the weights there are as expected. Not sure why just Substrate is reduced.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Comment on lines +75 to +76
fn template_rustfmt_works() {
if std::env::var("BENCHMARK_OVERHEAD_RUSTFMT").is_err() {
Copy link
Member Author

@ggwpez ggwpez Oct 12, 2022

Choose a reason for hiding this comment

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

Not sure how to handle this or if we want it.
It is pretty useful though since it is easy to mess up the template which then results in downstream fmt failure.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Nov 17, 2022
@paritytech paritytech deleted a comment from stale bot Nov 20, 2022
@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Nov 20, 2022
@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Dec 20, 2022
@paritytech paritytech deleted a comment from stale bot Dec 20, 2022
@ggwpez ggwpez removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Dec 20, 2022
@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Jan 19, 2023
@ggwpez ggwpez removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Jan 19, 2023
@paritytech paritytech deleted a comment from stale bot Jan 19, 2023
@stale stale bot added the A3-stale label Feb 19, 2023
@paritytech paritytech deleted a comment from stale bot Feb 19, 2023
@ggwpez ggwpez removed the A3-stale label Feb 19, 2023
@stale stale bot added the A3-stale label Mar 22, 2023
@ggwpez ggwpez removed the A3-stale label Mar 22, 2023
@paritytech paritytech deleted a comment from stale bot Mar 22, 2023
@stale
Copy link

stale bot commented Apr 21, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A3-stale label Apr 21, 2023
@ggwpez ggwpez removed the A3-stale label Apr 21, 2023
@stale
Copy link

stale bot commented May 21, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A3-stale label May 21, 2023
@stale stale bot closed this Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A3-in_progress Pull request is in progress. No review needed at this stage. A3-stale B0-silent Changes should not be mentioned in any release notes 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.

Record PoV size in benchmark overhead
2 participants