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

feat(pallet-api/fungibles): benchmark read functions #284

Merged
merged 7 commits into from
Sep 13, 2024

Conversation

peterwht
Copy link
Collaborator

@peterwht peterwht commented Sep 12, 2024

Solves #127

@peterwht peterwht changed the base branch from main to daan/api September 12, 2024 20:33

// Proof size is based on `MaxEncodedLen`, not hardware.
#[test]
fn ensure_expected_proof_size_does_not_change() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you want to double check this, please try on your machine!

./target/release/pop-node \
benchmark \
pallet \
--chain=dev \
--wasm-execution=compiled \
--pallet=fungibles \
--steps=50 \
--repeat=20 \
--json \
--template \
./scripts/pallet-weights-template.hbs \
--output=./pallets/api/src/fungibles/weights.rs \
--extrinsic=

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice if we also assert to the maxencodedlen of the structs from pallet assets maybe? How you did it previously

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

please see latest commit

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant a simple assert like the following:

		assert_eq!(allowance.proof_size(), Approval::<Balance, Balance>::max_encoded_len() as u64);

But that is incorrect. I'm not so sure whether all the additional test code in your last commit is worth it. Increases the burden to maintain and writing benchmarks is tmo a reason that we don't need to test the results in utter most detail.

cc @evilrobot-01

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah. Tbh when I saw your comment last night I thought the same, so had the same misunderstanding.

My view is that if we rely on the accuracy of benchmarks/weights for dispatchables, recreating it for reads seems unnecessary. There is a framework there for benchmarking and getting in-depth results out of it, so its reasonable to rely on it as that is what underpins the ecosystem. Fine for some additional sanity checks tho.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Whilst I admire the level of detail, clarity and accuracy of these tests, my only reservation would be whether this would become an expectation moving forward. My concern would be the additional time required to implement for all the other APIs to remain consistent versus the value it brings.

Copy link
Collaborator

@Daanvdplas Daanvdplas Sep 13, 2024

Choose a reason for hiding this comment

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

Same, therefore I think it is best to remove.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the clear detailed docs and tests though Peter, was able to immediately grasp the detailed workings of it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was quite tedious to do! Although thankful for the learnings :) The last test that verifies the proof size remains the same will effectively provide the same testing outcome (make sure the max_encoded_len does not change) please see the latest commit, reverting the changes.

Copy link
Collaborator

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

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

Really nice! Left a few nitpicks but then good to go!

pallets/api/src/fungibles/benchmarking.rs Show resolved Hide resolved

// Proof size is based on `MaxEncodedLen`, not hardware.
#[test]
fn ensure_expected_proof_size_does_not_change() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice if we also assert to the maxencodedlen of the structs from pallet assets maybe? How you did it previously

pallets/api/src/fungibles/mod.rs Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 68.50000% with 63 lines in your changes missing coverage. Please review.

Project coverage is 46.97%. Comparing base (206757b) to head (680e248).
Report is 2 commits behind head on daan/api.

Files with missing lines Patch % Lines
pallets/api/src/fungibles/weights.rs 50.00% 63 Missing ⚠️
@@             Coverage Diff              @@
##           daan/api     #284      +/-   ##
============================================
+ Coverage     42.59%   46.97%   +4.37%     
============================================
  Files            47       47              
  Lines          4139     4460     +321     
  Branches       4139     4460     +321     
============================================
+ Hits           1763     2095     +332     
+ Misses         2319     2303      -16     
- Partials         57       62       +5     
Files with missing lines Coverage Δ
pallets/api/src/fungibles/benchmarking.rs 100.00% <ø> (ø)
pallets/api/src/fungibles/mod.rs 85.48% <100.00%> (+2.70%) ⬆️
pallets/api/src/fungibles/tests.rs 100.00% <100.00%> (ø)
pallets/api/src/fungibles/weights.rs 50.00% <50.00%> (ø)

... and 6 files with indirect coverage changes

Copy link
Collaborator

@evilrobot-01 evilrobot-01 left a comment

Choose a reason for hiding this comment

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

Minor suggestion.

Also think the level of detail of tests needs considering, as mentioned inline.

pallets/api/src/fungibles/benchmarking.rs Outdated Show resolved Hide resolved

// Proof size is based on `MaxEncodedLen`, not hardware.
#[test]
fn ensure_expected_proof_size_does_not_change() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whilst I admire the level of detail, clarity and accuracy of these tests, my only reservation would be whether this would become an expectation moving forward. My concern would be the additional time required to implement for all the other APIs to remain consistent versus the value it brings.

@peterwht peterwht merged commit 5f92dab into daan/api Sep 13, 2024
10 checks passed
@peterwht peterwht deleted the peter/feat-api-read-weight branch September 13, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants