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

[SC-583] Optimize AddressArray and AddressSet libs #61

Merged
merged 24 commits into from
Mar 22, 2024

Conversation

k06a
Copy link
Member

@k06a k06a commented Jan 3, 2023

·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  get     ·  23901  ·  28945  ·  25539  ·  10  │
·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  length  ·      -  ·      -  ·  23359  ·   2  │
·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  pop     ·  21683  ·  26767  ·  24225  ·   4  │
·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  push    ·  44145  ·  49192  ·  46307  ·  28  │
·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  set     ·  27166  ·  29253  ·  27866  ·   3  │
·····················|··········|·········|·········|·········|·······
|  AddressSetMock    ·  add     ·  66455  ·  71502  ·  67939  ·  17  │
·····················|··········|·········|·········|·········|·······
|  AddressSetMock    ·  remove  ·  25948  ·  34664  ·  30306  ·   2  │
·····················|··········|·········|·········|·········|·······

=>

·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  get     ·  23730  ·  28353  ·  25162  ·  10  │
·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  length  ·      -  ·      -  ·  23347  ·   2  │
·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  pop     ·  26488  ·  28510  ·  27499  ·   4  │
·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  push    ·  43993  ·  49015  ·  46144  ·  28  │
·····················|··········|·········|·········|·········|·······
|  AddressArrayMock  ·  set     ·  27055  ·  29171  ·  27764  ·   3  │
·····················|··········|·········|·········|·········|·······
|  AddressSetMock    ·  add     ·  66295  ·  71317  ·  67772  ·  17  │
·····················|··········|·········|·········|·········|·······
|  AddressSetMock    ·  remove  ·  27525  ·  29547  ·  28536  ·   2  │
·····················|··········|·········|·········|·········|·······

@k06a k06a changed the title Optimize address array Optimize AddressArray and AddressSet libs Jan 3, 2023
@codecov
Copy link

codecov bot commented Jan 12, 2023

Codecov Report

Attention: Patch coverage is 60.97561% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 93.15%. Comparing base (4664c8d) to head (cdee296).

Files Patch % Lines
contracts/libraries/AddressSet.sol 50.00% 10 Missing ⚠️
contracts/libraries/AddressArray.sol 71.42% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
- Coverage   97.36%   93.15%   -4.21%     
==========================================
  Files          16       16              
  Lines         341      336       -5     
  Branches       71       66       -5     
==========================================
- Hits          332      313      -19     
- Misses          9       23      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ZumZoom ZumZoom changed the title Optimize AddressArray and AddressSet libs [SC-583] Optimize AddressArray and AddressSet libs Apr 7, 2023
# Conflicts:
#	test/contracts/AddressArray.test.ts
@zZoMROT
Copy link
Contributor

zZoMROT commented Nov 17, 2023

·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  get        ·      23825  ·      28743  ·      25394  ·  10  ·
·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  length     ·          -  ·          -  ·      23404  ·   2  ·
·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  pop        ·      21677  ·      26747  ·      24212  ·   4  ·
·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  push       ·      43986  ·      48980  ·      46125  ·  28  ·
·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  set        ·      26903  ·      29011  ·      27610  ·   3  ·
·····················|·············|·············|·············|·············|······|
|  AddressSetMock    ·  add        ·      66097  ·      71137  ·      67579  ·  17  ·
·····················|·············|·············|·············|·············|······|
|  AddressSetMock    ·  remove     ·      25819  ·      34322  ·      30071  ·   2  ·
·····················|·············|·············|·············|·············|······|

=>

·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  get        ·      23590  ·      28211  ·      25024  ·  10  ·
·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  length     ·          -  ·          -  ·      23329  ·   2  ·
·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  pop        ·      26371  ·      26382  ·      26377  ·   4  ·
·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  push       ·      43864  ·      48862  ·      46005  ·  28  ·
·····················|·············|·············|·············|·············|······|
|  AddressArrayMock  ·  set        ·      26860  ·      28957  ·      27563  ·   3  ·
·····················|·············|·············|·············|·············|······|
|  AddressSetMock    ·  add        ·      66046  ·      71044  ·      67516  ·  17  ·
·····················|·············|·············|·············|·············|······|
|  AddressSetMock    ·  remove     ·      32148  ·      34243  ·      33196  ·   2  ·
·····················|·············|·············|·············|·············|······|

pop and remove are worse

@k06a
Copy link
Member Author

k06a commented Nov 17, 2023

@zZoMROT pop() didn't receive 5k gas refund, but optimizes future push() by 15k.

@ZumZoom
Copy link
Member

ZumZoom commented Mar 21, 2024

·····················|··············|·············|·············|·················|···············|
|  Contract          ·  Method      ·  Min        ·  Max        ·  Avg            ·  # calls      ·
·····················|··············|·············|·············|·················|···············|
|  AddressArrayMock  ·  pop         ·      21677  ·      26747  ·          24212  ·            4  ·
·····················|··············|·············|·············|·················|···············|
|  AddressArrayMock  ·  push        ·      43986  ·      48980  ·          46125  ·           28  ·
·····················|··············|·············|·············|·················|···············|
|  AddressArrayMock  ·  set         ·      26903  ·      29011  ·          27610  ·            3  ·
·····················|··············|·············|·············|·················|···············|
|  AddressSetMock    ·  add         ·      66097  ·      71137  ·          67579  ·           17  ·
·····················|··············|·············|·············|·················|···············|
|  AddressSetMock    ·  remove      ·      25819  ·      34322  ·          30071  ·            2  ·
·····················|··············|·············|·············|·················|···············|
|  TokenWithBySig    ·  bySig       ·      86539  ·     144238  ·         113485  ·            8  ·
·····················|··············|·············|·············|·················|···············|

=>

·····················|··············|·············|·············|·················|···············|
|  Contract          ·  Method      ·  Min        ·  Max        ·  Avg            ·  # calls      ·
·····················|··············|·············|·············|·················|···············|
|  AddressArrayMock  ·  pop         ·          -  ·          -  ·          26363  ·            4  ·
·····················|··············|·············|·············|·················|···············|
|  AddressArrayMock  ·  push        ·      43864  ·      48862  ·          46005  ·           28  ·
·····················|··············|·············|·············|·················|···············|
|  AddressArrayMock  ·  set         ·      26832  ·      28942  ·          27539  ·            3  ·
·····················|··············|·············|·············|·················|···············|
|  AddressSetMock    ·  add         ·      66046  ·      71044  ·          67516  ·           17  ·
·····················|··············|·············|·············|·················|···············|
|  AddressSetMock    ·  remove      ·      32021  ·      39502  ·          35762  ·            2  ·
·····················|··············|·············|·············|·················|···············|
|  TokenWithBySig    ·  bySig       ·     106120  ·     179414  ·         139979  ·            8  ·
·····················|··············|·············|·············|·················|···············|

ZumZoom
ZumZoom previously approved these changes Mar 21, 2024
@ZumZoom
Copy link
Member

ZumZoom commented Mar 22, 2024

Multi push/pop tests that show how dirty storage affects add/push:

·····················|··········|·············|·············|·················|
|  AddressSetMock    ·  add     ·      66097  ·      71137  ·          68617  ·
·····················|··········|·············|·············|·················|
|  AddressSetMock    ·  remove  ·      25819  ·      29883  ·          27851  ·
·····················|··········|·············|·············|·················|
|  AddressArrayMock  ·  pop     ·      21677  ·      26747  ·          24212  ·
·····················|··········|·············|·············|·················|
|  AddressArrayMock  ·  push    ·      43986  ·      48980  ·          46483  ·
·····················|··········|·············|·············|·················|

=>

·····················|··········|·············|·············|·················|
|  AddressSetMock    ·  add     ·      31874  ·      71044  ·          50759  ·
·····················|··········|·············|·············|·················|
|  AddressSetMock    ·  remove  ·      32021  ·      34116  ·          33069  ·
·····················|··········|·············|·············|·················|
|  AddressArrayMock  ·  pop     ·          -  ·          -  ·          26363  ·
·····················|··········|·············|·············|·················|
|  AddressArrayMock  ·  push    ·      26764  ·      48862  ·          37113  ·
·····················|··········|·············|·············|·················|

tldr:

AddressSet.add     -34K
AddressSet.remove  +4.5K
AddressArray.push  -17K
AddressArray.pop   +4.5K

@ZumZoom ZumZoom merged commit 5ca7647 into master Mar 22, 2024
6 of 8 checks passed
@ZumZoom ZumZoom deleted the feature/optimize-address-array branch March 22, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants