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

Cleanup String::from_utf8 #3446

Merged
merged 10 commits into from Feb 26, 2024
Merged

Conversation

philoniare
Copy link
Contributor

Description

*Refactors String::from_utf8 usage in the pallet benchmarking

Fixes #389

@philoniare philoniare marked this pull request as ready for review February 24, 2024 02:01
@@ -329,12 +335,12 @@ impl PalletCmd {
let mut component_ranges = HashMap::<(Vec<u8>, Vec<u8>), Vec<ComponentRange>>::new();
let pov_modes = Self::parse_pov_modes(&benchmarks_to_run)?;

for (pallet, extrinsic, components, _) in benchmarks_to_run.clone() {
for (pallet, extrinsic, components, _, pallet_str, extrinsic_str) in benchmarks_to_run.clone() {
log::info!(
target: LOG_TARGET,
"Starting benchmark: {}::{}",
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
"Starting benchmark: {}::{}",
"Starting benchmark: {pallet_str}::{extrinsic_str}",

Comment on lines 342 to 343
pallet_str,
extrinsic_str,
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
pallet_str,
extrinsic_str,

@@ -417,8 +423,8 @@ impl PalletCmd {
.map_err(|e| {
format!(
"Benchmark {}::{} failed: {}",
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
"Benchmark {}::{} failed: {}",
"Benchmark {pallet_str}::{extrinsic_str} failed: {e}",

Comment on lines 426 to 428
pallet_str,
extrinsic_str,
e
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
pallet_str,
extrinsic_str,
e

@@ -495,10 +501,8 @@ impl PalletCmd {
log::info!(
target: LOG_TARGET,
"Running benchmark: {}.{}({} args) {}/{} {}/{}",
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
"Running benchmark: {}.{}({} args) {}/{} {}/{}",
"Running benchmark: {pallet_str}.{extrinsic_str}({} args) {}/{} {}/{}",

Comment on lines 504 to 505
pallet_str,
extrinsic_str,
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
pallet_str,
extrinsic_str,

let pallet = String::from_utf8(key_info.pallet_name.clone())
.expect("encoded from string");
let item = String::from_utf8(key_info.storage_name.clone())
.expect("encoded from string");
let comment = format!(
"Proof: `{}::{}` (`max_values`: {:?}, `max_size`: {:?}, mode: `{:?}`)",
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
"Proof: `{}::{}` (`max_values`: {:?}, `max_size`: {:?}, mode: `{:?}`)",
"Proof: `{pallet_name}::{storage_name}` (`max_values`: {:?}, `max_size`: {:?}, mode: `{:?}`)",

let comment = format!(
"Proof: `{}::{}` (`max_values`: {:?}, `max_size`: {:?}, mode: `{:?}`)",
pallet, item, key_info.max_values, key_info.max_size,
pallet_name, storage_name, key_info.max_values, key_info.max_size,
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
pallet_name, storage_name, key_info.max_values, key_info.max_size,
key_info.max_values, key_info.max_size,

@bkchr bkchr added the R0-silent Changes should not be mentioned in any release notes label Feb 25, 2024
@bkchr bkchr requested a review from ggwpez February 25, 2024 22:02
Comment on lines 302 to 304
let pallet_str = String::from_utf8(pallet.clone()).expect("Encoded from String; qed");
let extrinsic_str = String::from_utf8(extrinsic.clone()).expect("Encoded from String; qed");
let pov_modes_str = pov_modes.into_iter()
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick. In general we don't use Hungarian notation or any variation of it. So in this case I'd rename these variables to just pallet_name, extrinsic_name and pov_modes (as done some files below - writer.rs?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, sure thing. I've updated the variable names for pallet_str, extrinsic_str and removed pov_modes_str as pov_modes was already being passed in

@philoniare
Copy link
Contributor Author

Thanks for the review @bkchr, all of the comments have been addressed

@@ -329,12 +333,10 @@ impl PalletCmd {
let mut component_ranges = HashMap::<(Vec<u8>, Vec<u8>), Vec<ComponentRange>>::new();
let pov_modes = Self::parse_pov_modes(&benchmarks_to_run)?;

for (pallet, extrinsic, components, _) in benchmarks_to_run.clone() {
for (pallet, extrinsic, components, _, pallet_str, extrinsic_str) in benchmarks_to_run.clone() {
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
for (pallet, extrinsic, components, _, pallet_str, extrinsic_str) in benchmarks_to_run.clone() {
for (pallet, extrinsic, components, _, pallet, extrinsic) in benchmarks_to_run.clone() {

Types dont need to be in the var name.

Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Thanks!

.expect("Encoded from String; qed"),
String::from_utf8(extrinsic.clone())
.expect("Encoded from String; qed"),
"Running benchmark: {pallet_str}.{extrinsic_str}({} args) {}/{} {}/{}",
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
"Running benchmark: {pallet_str}.{extrinsic_str}({} args) {}/{} {}/{}",
"Running benchmark: {pallet_str}::{extrinsic_str}({} args) {}/{} {}/{}",

Noticed recently that it should be consistent with the print above.

let pallet_string = String::from_utf8(batch.pallet.clone()).unwrap();
let instance_string = String::from_utf8(batch.instance.clone()).unwrap();
let pallet_name = String::from_utf8(batch.pallet.clone()).unwrap();
let instance_name = String::from_utf8(batch.instance.clone()).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Originally i thought that already the types in BenchmarkBatchSplitResults and BenchmarkBatch should be converted, but it would mean to duplicate or generitize the types.
Guess this is a good start for now.

@ggwpez
Copy link
Member

ggwpez commented Feb 26, 2024

bot fmt

@command-bot
Copy link

command-bot bot commented Feb 26, 2024

@ggwpez https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5348374 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 1-44b231b3-8b81-4a68-a363-f82dc97114cb to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Feb 26, 2024

@ggwpez Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5348374 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5348374/artifacts/download.

@ggwpez ggwpez added this pull request to the merge queue Feb 26, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Feb 26, 2024
@ggwpez ggwpez added this pull request to the merge queue Feb 26, 2024
Merged via the queue into paritytech:master with commit 81d447a Feb 26, 2024
128 of 130 checks passed
ordian added a commit that referenced this pull request Feb 28, 2024
…head-data

* origin/master: (51 commits)
  Runtime Upgrade ref docs and Single Block Migration example pallet  (#1554)
  Collator overseer builder unification (#3335)
  Introduce storage attr macro `#[disable_try_decode_storage]` and set it on `System::Events` and `ParachainSystem::HostConfiguration` (#3454)
  Add Polkadotters bootnoders per IBP application (#3423)
  Add documentation around FRAME Origin (#3362)
  Bridge zombienet tests: Check amount received at destination (#3490)
  Snowbridge benchmark tests fix (#3424)
  fix(zombienet): increase timeout in download artifacts (#3376)
  Cleanup String::from_utf8 (#3446)
  [prdoc] Validate crate names (#3467)
  Limit max execution time for `test-linux-stable` CI jobs (#3483)
  Introduce Notification block pinning limit (#2935)
  frame-support: Improve error reporting when having too many pallets (#3478)
  add Encointer as trusted teleporter for Westend (#3411)
  [pallet-xcm] Adjust benchmarks (teleport_assets/reserve_transfer_assets) not relying on ED (#3464)
  Add more debug logs to understand if statement-distribution misbehaving (#3419)
  Remove redundant parachains assigner pallet. (#3457)
  Use generic hash for runtime wasm in resolve_state_version_from_wasm (#3447)
  Runtime: allow backing multiple candidates of same parachain on different cores  (#3231)
  Bridge zombienet tests: move all "framework" files under one folder (#3462)
  ...
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
# Description

*Refactors `String::from_utf8` usage in the pallet benchmarking

Fixes paritytech#389

---------

Co-authored-by: command-bot <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup String::from_utf8 usage in the pallet benchmarking
4 participants