X Tutup
The Wayback Machine - https://web.archive.org/web/20201018172604/https://github.com/paritytech/substrate/pull/7233
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

Constant Weight Signature in Benchmarking CLI #7233

Merged
merged 10 commits into from Oct 17, 2020

Conversation

@shawntabrizi
Copy link
Member

@shawntabrizi shawntabrizi commented Sep 29, 2020

polkadot companion: paritytech/polkadot#1791

This PR fixes a dumb choice I made about hiding variables when they are not used in the weight formula at the end of the benchmarking pipeline.

What I realize now is that our fitting algorithm is not perfect, and may associate some weight to a component depending on the results of the benchmark. If it does this one time, and not another time, then the entire signature of the weight formula would change, making it incompatible at the trait definition layer.

Instead of removing the variable from the function definition, I simply omit usage of the variable by adding a _.

This will keep the function signature the same, but also be a clear indicator that the variable is not being used.

If a variable does not need to be included in the formula at all, it is on the benchmark writer to omit this as one of the components.

@shawntabrizi shawntabrizi added this to In progress in Benchmarking and Weights via automation Sep 29, 2020
@shawntabrizi shawntabrizi moved this from In progress to Done in Benchmarking and Weights Sep 29, 2020
@shawntabrizi shawntabrizi added B0-silent and removed D0-patchthis labels Sep 29, 2020
@bkchr
bkchr approved these changes Sep 29, 2020
utils/frame/benchmarking-cli/src/writer.rs Outdated Show resolved Hide resolved
@bkchr
Copy link
Contributor

@bkchr bkchr commented Oct 2, 2020

@shawntabrizi please merge master

@shawntabrizi shawntabrizi mentioned this pull request Oct 6, 2020
0 of 8 tasks complete
@shawntabrizi shawntabrizi marked this pull request as draft Oct 7, 2020
shawntabrizi added 2 commits Oct 7, 2020
This reverts commit ce522c3.
@shawntabrizi shawntabrizi marked this pull request as ready for review Oct 7, 2020
@shawntabrizi shawntabrizi requested review from thiolliere and bkchr Oct 7, 2020
frame/timestamp/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@thiolliere thiolliere left a comment

PR is good to me,
I'm still uncertain about inter-pallet logic stuff and how it should documented, but this discussion don't belong to this PR IMHO

frame/utility/src/lib.rs Outdated Show resolved Hide resolved
@@ -159,9 +159,9 @@ decl_module! {
/// The dispatch origin for this call must be `Inherent`.
///
/// # <weight>
/// - `O(T)` where `T` complexity of `on_timestamp_set`
/// - `O(1)` (Note that implementations of `OnTimestampSet` must also be `O(1)`)

This comment has been minimized.

@thiolliere

thiolliere Oct 14, 2020
Contributor

Even if OnTimestampSet is O(1) the benchmark might miss some read/writes and base cost.

benchmark only call on_timestamp_set(100), but maybe on_timestamp_set(100) is 1 storage read whereas on_timestamp_set(200) will trigger some storage writes because some period are over or something.

like if a module do 100 storage writes every minutes. (obviously in this case such a pallet should be refactored to use on_initialize, but my point is that such implementation is O(1)).

maybe we can document that on_timestamp_set should always cost its worst case, although this is an annoying constraint.
or maybe I miss something in the picture here.

(note aside, I don't think this is that much of an issue here, I just wonder about general usage of handler)

This comment has been minimized.

@shawntabrizi

shawntabrizi Oct 15, 2020
Author Member

O(1) means constant time right? i.e. this function should always have the same weight independent of the input.

This comment has been minimized.

@thiolliere

thiolliere Oct 15, 2020
Contributor

I think constant time means there is an upper bound independant from input.
the following code is constant time:

fn foo(a: u32) {
  if a > 10 {
    do 2 writes
  }
}

https://en.wikipedia.org/wiki/Time_complexity#Constant_time

This comment has been minimized.

@shawntabrizi

shawntabrizi Oct 15, 2020
Author Member

Yeah, I am not sure what else I can do in this case then.

@gavofyork
Copy link
Member

@gavofyork gavofyork commented Oct 17, 2020

bot merge

@parity-processbot
Copy link
Contributor

@parity-processbot parity-processbot bot commented Oct 17, 2020

Trying merge.

@parity-processbot parity-processbot bot merged commit 900d034 into master Oct 17, 2020
21 checks passed
21 checks passed
check_status
Details
notify-devops
Details
continuous-integration/gitlab-build-rust-doc Build stage: build; status: success
Details
continuous-integration/gitlab-cargo-check-benches Build stage: test; status: success
Details
continuous-integration/gitlab-cargo-check-macos Build stage: test; status: success
Details
continuous-integration/gitlab-cargo-check-subkey Build stage: test; status: success
Details
continuous-integration/gitlab-check-labels Build stage: .post; status: success
Details
continuous-integration/gitlab-check-line-width Build stage: check; status: success
Details
continuous-integration/gitlab-check-polkadot-companion-build Build stage: build; status: success
Details
continuous-integration/gitlab-check-polkadot-companion-status Build stage: build; status: success
Details
continuous-integration/gitlab-check-runtime Build stage: check; status: success
Details
continuous-integration/gitlab-check-web-wasm Build stage: test; status: success
Details
continuous-integration/gitlab-skip-if-draft Build stage: .pre; status: success
Details
continuous-integration/gitlab-test-browser-node Build stage: build; status: success
Details
continuous-integration/gitlab-test-dependency-rules Build stage: check; status: success
Details
continuous-integration/gitlab-test-deterministic-wasm Build stage: test; status: success
Details
continuous-integration/gitlab-test-frame-examples-compile-to-wasm Build stage: test; status: success
Details
continuous-integration/gitlab-test-full-crypto-feature Build stage: test; status: success
Details
continuous-integration/gitlab-test-linux-stable Build stage: test; status: success
Details
continuous-integration/gitlab-test-linux-stable-int Build stage: test; status: success
Details
continuous-integration/gitlab-test-prometheus-alerting-rules Build stage: test; status: success
Details
@parity-processbot parity-processbot bot deleted the shawntabrizi-constant-weight-signature branch Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.
X Tutup