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

Optimized gas usage when writing objects #633

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

Ronnieraj37
Copy link
Contributor

@Ronnieraj37 Ronnieraj37 commented Oct 30, 2024

Why This Should Be Merged

As discussed in Issue #613 , I tested various methods for allocating objects, evaluating each for gas optimization to determine the most efficient approach.

How This Works

When assigning mappings within an object, individually assigning each item proved more gas-efficient than assigning the entire object at once. For objects without mappings, however, assigning the whole object was generally more efficient.

How This Was Tested

I ran comprehensive tests, with the following results showing gas usage improvements:

Function Name Initial Gas New Gas Gas Saved
testCumulativeChurnRegistrationAndEndValidation() 744,442 743,364 1,078
testForceInitializeEndDelegation() 585,201 584,394 807
testForceInitializeEndDelegationInsufficientUptime() 532,187 531,380 807
testForceInitializeEndValidation() 489,396 488,856 540
testForceInitializeEndValidationInsufficientUptime() 475,388 474,849 539
testInitialWeightsTooLow() 5,509,390 5,434,967 74,423

Documentation

Code has been updated as noted in Issue #628.

@cam-schultz Avoiding a branched object increased gas costs for standard operations but provided significant savings during revert scenarios. For example, in testInitialWeightsTooLow(), gas usage decreased from 5,446,569 to 5,434,967, saving approximately 12K gas from the previous adjustment and totalling a ~74K gas reduction. Thanks for recommending this change!

@cam-schultz
Copy link
Contributor

@Ronnieraj37 we require all commits to be signed. Can you please replay de2cd12 and and make sure it is signed?

@Ronnieraj37 Ronnieraj37 reopened this Oct 31, 2024
@Ronnieraj37
Copy link
Contributor Author

Hey @cam-schultz I was having some problem committing the exact message so I removed those commits and created a new verified commit.

@cam-schultz cam-schultz merged commit 75de9b7 into ava-labs:main Oct 31, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done ✅
Development

Successfully merging this pull request may close these issues.

4 participants