Optimized gas usage when writing objects #628
                
     Closed
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Why This Should Be Merged
As discussed in issue #613 , I experimented with various methods for allocating objects and thoroughly tested each to determine the most efficient approach for gas optimization.
How This Works
When assigning mappings within an object, I found that individually assigning each item in the object was more efficient than assigning the entire object at once. However, for objects without mappings, a complete assignment was generally more efficient.
How This Was Tested
I ran all tests and observed the following gas usage reports:
testCumulativeChurnRegistrationAndEndValidation()testForceInitializeEndDelegation()testForceInitializeEndDelegationInsufficientUptime()testForceInitializeEndValidation()testForceInitializeEndValidationInsufficientUptime()testInitialWeightsTooLow()View Complete Report
Summary of Gas Changes for These Tests
Documentation
For each object assigned more efficiently, I have included comments marked as:
// Efficient AssignmentAdditional Modifications
The object
PoSValidatorManagerStoragewas restructured by separating certain fields into a newPoSValidatorManagerConfigobject, as this improved assignment efficiency.While this adjustment affects readability, I can remove it if preferred. Additionally, a similar implementation can be applied to
ValidatorManagerStorage, but I have left it unchanged for now to confirm if this approach should be universally adopted.