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

Add asymptotic fallback ranges #65

Merged
merged 8 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
935 changes: 495 additions & 440 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
cargo-features = ["strip"]

[workspace.package]
edition = "2021"
authors = ["Oliver Tale-Yazdi <[email protected]>"]
version = "3.4.2"
version = "3.4.3"
repository = "https://github.com/ggwpez/substrate-weight-compare"
readme = "README.md"
keywords = [ "polkadot", "substrate", "blockchain" ]
Expand All @@ -20,11 +18,11 @@ members = [
resolver = "2"

[workspace.dependencies]
subweight-core = { version = "3.4.2", path = "core" }
subweight-core = { version = "3.4.3", path = "core" }

clap = { version = "4.5.4", features = ["derive"] }
env_logger = "0.11.3"
log = "0.4.21"
clap = { version = "4.5.16", features = ["derive"] }
env_logger = "0.11.5"
log = "0.4.22"
sailfish = { version = "0.8.3" }

[profile.test-release]
Expand All @@ -37,6 +35,6 @@ debug-assertions = true
[profile.production]
inherits = "release"
lto = "fat"
codegen-units = 1
strip = true
codegen-units = 1
opt-level = "z"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ This is a deciding factor when making a decision whether or not a weight got wor
- *Exact Worst*: Assumes both equations to be hyper-planes and finds their greatest relative increase by evaluating all corners. The runtime for `n` components is `2^n` which is hard-limited to 16 components.
This requires your weight files to support [component range annotations](https://github.com/paritytech/substrate/issues/11397). One way to check that is to search for the string `"The range of component"` in your weight.rs files.
- *Guess Worst*: Tries to apply *Exact Worst* but assumes all components to have a maximum of 100, if no maximum was found. This is a best-effort approach in case your weight files do not have component range annotations.
- *Asymptotic*: Set all components to their maximum value. Can be used to get a feeling for the asymptotic change of the formula.
- *Exact Asymptotic*: Set all components to their maximum value. Can be used to get a feeling for the asymptotic change of the formula.
- *Asymptotic*: Same as *Exact Asymptotic* but fallback to best-effort ranges if no compatible ones could be found.

NOTE: The storage weights are currently set to RocksDB Substrate default.

Expand Down
10 changes: 5 additions & 5 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ env_logger.workspace = true
log.workspace = true
clap.workspace = true

syn = { version = "2.0.55", features = ["parsing", "full"] }
comfy-table = { version = "7.1.0", default-features = false }
serde = { version = "1.0.197", features = [ "derive" ] }
syn = { version = "2.0.74", features = ["parsing", "full"] }
comfy-table = { version = "7.1.1", default-features = false }
serde = { version = "1.0.208", features = [ "derive" ] }
fancy-regex = "0.13.0"

[dev-dependencies]
assert_cmd = "2.0.14"
serial_test = "3.0.0"
assert_cmd = "2.0.16"
serial_test = "3.1.1"
16 changes: 8 additions & 8 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ log.workspace = true
fancy-regex = "0.13.0"
git-version = "0.3.9"
glob = "0.3.1"
lazy_static = "1.4.0"
proc-macro2 = "1.0.79"
semver = "1.0.22"
serde = { version = "1.0.197", features = [ "derive" ] }
serde_json = "1.0.115"
syn = { version = "2.0.55", features = ["parsing", "full"] }
lazy_static = "1.5.0"
proc-macro2 = "1.0.86"
semver = "1.0.23"
serde = { version = "1.0.208", features = [ "derive" ] }
serde_json = "1.0.125"
syn = { version = "2.0.74", features = ["parsing", "full"] }

[dev-dependencies]
criterion = { version = "0.5", features = [ "html_reports" ] }
rstest = "0.18.2"
serial_test = "3.0.0"
rstest = "0.22.0"
serial_test = "3.1.1"
maplit = "1.0.2"

# Work-around for <https://github.com/rust-lang/cargo/issues/2911>
Expand Down
18 changes: 14 additions & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub enum CompareMethod {
/// Similar to [`Self::ExactWorst`], but guesses if any component misses a range annotation.
GuessWorst,
/// Set all components to their exact maximum value.
ExactAsymptotic,
Asymptotic,
}

Expand All @@ -348,15 +349,17 @@ impl CompareMethod {
match self {
Self::Base | Self::GuessWorst => ComponentInstanceStrategy::guess_min(),
Self::ExactWorst => ComponentInstanceStrategy::exact_min(),
Self::Asymptotic => ComponentInstanceStrategy::exact_max(),
Self::ExactAsymptotic => ComponentInstanceStrategy::exact_max(),
Self::Asymptotic => ComponentInstanceStrategy::guess_max(),
}
}

pub const fn max(&self) -> ComponentInstanceStrategy {
match self {
Self::Base => ComponentInstanceStrategy::guess_min(),
Self::GuessWorst => ComponentInstanceStrategy::guess_max(),
Self::ExactWorst | Self::Asymptotic => ComponentInstanceStrategy::exact_max(),
Self::ExactWorst | Self::ExactAsymptotic => ComponentInstanceStrategy::exact_max(),
Self::Asymptotic => ComponentInstanceStrategy::guess_max(),
}
}
}
Expand Down Expand Up @@ -420,6 +423,7 @@ impl std::str::FromStr for CompareMethod {
"base" => Ok(CompareMethod::Base),
"guess-worst" => Ok(CompareMethod::GuessWorst),
"exact-worst" => Ok(CompareMethod::ExactWorst),
"exact-asymptotic" => Ok(CompareMethod::ExactAsymptotic),
"asymptotic" => Ok(CompareMethod::Asymptotic),
_ => Err(format!("Unknown method: {}", s)),
}
Expand All @@ -428,11 +432,17 @@ impl std::str::FromStr for CompareMethod {

impl CompareMethod {
pub fn all() -> Vec<Self> {
vec![Self::Base, Self::GuessWorst, Self::ExactWorst, Self::Asymptotic]
vec![
Self::Base,
Self::GuessWorst,
Self::ExactWorst,
Self::ExactAsymptotic,
Self::Asymptotic,
]
}

pub fn variants() -> Vec<&'static str> {
vec!["base", "guess-worst", "exact-worst", "asymptotic"]
vec!["base", "guess-worst", "exact-worst", "exact-asymptotic", "asymptotic"]
}

pub fn reflect() -> Vec<(Self, &'static str)> {
Expand Down
2 changes: 1 addition & 1 deletion core/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where
}

pub fn get(&self, name: &str) -> Option<T> {
self.vars.get(&name.to_string()).cloned()
self.vars.get(name).cloned()
}

pub fn merge(self, other: Self) -> Self {
Expand Down
6 changes: 6 additions & 0 deletions core/src/test/parse/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ macro_rules! integration_test {
overhead_files: Vec<PathBuf>,
) {
for f in &rust_files {
let path = std::fs::canonicalize(f).unwrap();
let f = &path;

match $crate::parse::try_parse_file(Path::new("."), f){
None => if pallet_files.contains(f) {
let err = $crate::parse::pallet::parse_file(f).unwrap_err();
Expand Down Expand Up @@ -142,6 +145,7 @@ macro_rules! integration_test {
)
})
.flatten()
.map(|f| std::fs::canonicalize(f).unwrap())
.collect()
}

Expand All @@ -156,6 +160,7 @@ macro_rules! integration_test {
glob(&pattern).unwrap().map(|f| f.unwrap())
})
.flatten()
.map(|f| std::fs::canonicalize(f).unwrap())
.collect()
}

Expand All @@ -170,6 +175,7 @@ macro_rules! integration_test {
glob(&pattern).unwrap().map(|f| f.unwrap())
})
.flatten()
.map(|f| std::fs::canonicalize(f).unwrap())
.collect()
}

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.74.0"
channel = "1.80.0"
components = [ "rustfmt", "clippy" ]
profile = "minimal"
24 changes: 12 additions & 12 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ env_logger.workspace = true
log.workspace = true
sailfish.workspace = true

actix-web = { version = "4.5.1", features = ["openssl"] }
actix-files = "0.6.5"
lazy_static = "1.4.0"
actix-web = { version = "4.9.0", features = ["openssl"] }
actix-files = "0.6.6"
lazy_static = "1.5.0"
openssl = { version = "0.10", features = ["v110"] }
syn = { version = "2.0.55", features = ["parsing", "full"] }
serde = { version = "1.0.197", features = [ "derive" ] }
syn = { version = "2.0.74", features = ["parsing", "full"] }
serde = { version = "1.0.208", features = [ "derive" ] }
badge-maker = "0.3.1"
dashmap = "5.5.3"
cached = "0.49.2"
dashmap = "6.0.1"
cached = "0.53.1"
fancy-regex = "0.13.0"
html-escape = "0.2.13"

[dev-dependencies]
assert_cmd = "2.0.14"
serial_test = "3.0.0"
reqwest = { version = "0.12.2", default-features = false, features = ["blocking"] }
tempfile = "3.10.1"
rstest = { version = "0.18.2", default-features = false }
assert_cmd = "2.0.16"
serial_test = "3.1.1"
reqwest = { version = "0.12.5", default-features = false, features = ["blocking"] }
tempfile = "3.12.0"
rstest = { version = "0.22.0", default-features = false }
Loading