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

[do-not-merge] - packing gas testing #570

Closed
wants to merge 1 commit into from

Conversation

iansuvak
Copy link
Contributor

@iansuvak iansuvak commented Sep 23, 2024

Why this should be merged

It shouldn't just a demo of testing packing efficency. If there are no problems with the testing method I will cut a PR to replace the existing packing method with the old one and keep the testing helpers to cover cases with multiple validators.

How this works

  • Creates helper methods to generate subnetconversiondata with parametrized number of initialvalidators in _defaultSubnetConversionData
  • Defines a _oldSubnetConversionDataPack to mimic the previous method of using abi.encodePacked in a loop.
  • Defines 3 tests, 2 to test gas usage for old (abi.encodePacked)and new (manual byte by byte packing) methods, and a third one to ensure that their outputs match
  • Changed the input type from bytes calldata to bytes memory. This is a significant change since reading from calldata is a lot cheaper than memory but I don't think that it should change the outcome of the test since it's still an apples to apples comparison.

How this was tested

Ran manual forge tests with different num InitialValidators counts:
Below are the results showing that doing abi.encodePacked in a loop is a lot more efficient given this testing methodology.

- numValidators: 1
[PASS] testSubnetConversionDataPacking() (gas: 69619)
[PASS] testSubnetConversionDataPackingNew() (gas: 66295)
[PASS] testSubnetConversionDataPackingOld() (gas: 5204)

- numValidators: 5
[PASS] testSubnetConversionDataPacking() (gas: 222986)
[PASS] testSubnetConversionDataPackingNew() (gas: 211833)
[PASS] testSubnetConversionDataPackingOld() (gas: 14351)

- numValidators: 10
[PASS] testSubnetConversionDataPacking() (gas: 419291)
[PASS] testSubnetConversionDataPackingNew() (gas: 393842)
[PASS] testSubnetConversionDataPackingOld() (gas: 30222)

- numValidators: 50
[PASS] testSubnetConversionDataPacking() (gas: 2202742)
[PASS] testSubnetConversionDataPackingNew() (gas: 1851161)
[PASS] testSubnetConversionDataPackingOld() (gas: 363856)

How is this documented

@iansuvak iansuvak added the DO NOT MERGE This PR is not meant to be merged in its current state label Sep 23, 2024
@iansuvak iansuvak requested a review from a team as a code owner September 23, 2024 17:40
@iansuvak iansuvak marked this pull request as draft September 23, 2024 17:41
@iansuvak iansuvak changed the title packing gas testing [do-not-merge] - packing gas testing Sep 23, 2024
@iansuvak iansuvak closed this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE This PR is not meant to be merged in its current state
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant