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

pallet-revive: Fix the contract size related benchmarks #7568

Merged
merged 10 commits into from
Feb 14, 2025
Merged

Conversation

athei
Copy link
Member

@athei athei commented Feb 13, 2025

Partly addresses #6157

The benchmarks measuring the impact of contract sizes on calling or instantiating a contract were bogus because they needed to be written in assembly in order to tightly control the basic block size.

This fixes the benchmarks for:

  • call_with_code_per_byte
  • upload_code
  • instantiate_with_code

And adds a new benchmark that accounts for the fact that the interpreter will always compile whole basic blocks:

  • basic_block_compilation

After this PR only the weight we assign to instructions need to be addressed.

@athei athei added the T7-smart_contracts This PR/Issue is related to smart contracts. label Feb 13, 2025
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/13314171801
Failed job name: test-linux-stable

@github-actions github-actions bot deleted a comment from athei Feb 13, 2025
@athei
Copy link
Member Author

athei commented Feb 13, 2025

/cmd fmt --clean

@github-actions github-actions bot deleted a comment from athei Feb 13, 2025
@athei athei marked this pull request as ready for review February 14, 2025 00:01
pub fn sized(size: u32) -> Self {
// Due to variable length encoding of instructions this is not precise. But we only
// need rough numbers for our benchmarks.
Self::with_num_instructions(size / 3)
Copy link
Contributor

@smiasojed smiasojed Feb 14, 2025

Choose a reason for hiding this comment

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

Could you please explain why we divide by 3? Is it a minimal instruction size?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the average size of an instruction in the PolkaVM blob. But since it uses variable size encoding its not excact (see comment above). I played around a little with divisors until i get roughly the amount of instructions to hit the max blob size.

@athei athei added this pull request to the merge queue Feb 14, 2025
Merged via the queue into master with commit 60146ba Feb 14, 2025
220 of 235 checks passed
@athei athei deleted the at/fix-benchmarks branch February 14, 2025 13:53
clangenb pushed a commit to clangenb/polkadot-sdk that referenced this pull request Feb 19, 2025
)

Partly addresses paritytech#6157

The benchmarks measuring the impact of contract sizes on calling or
instantiating a contract were bogus because they needed to be written in
assembly in order to tightly control the basic block size.

This fixes the benchmarks for:
- call_with_code_per_byte
- upload_code
- instantiate_with_code

And adds a new benchmark that accounts for the fact that the interpreter
will always compile whole basic blocks:
- basic_block_compilation

After this PR only the weight we assign to instructions need to be
addressed.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T7-smart_contracts This PR/Issue is related to smart contracts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants