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

Address.functionCall internal call stack simplification #3468

Merged
merged 1 commit into from Jun 16, 2022
Merged

Address.functionCall internal call stack simplification #3468

merged 1 commit into from Jun 16, 2022

Conversation

ZumZoom
Copy link
Contributor

@ZumZoom ZumZoom commented Jun 13, 2022

It is a bit cheaper to call functionCallWithValue directly than via extra intermediate internal call. It also allows to save a bit on contract size in case of functionCall(address,bytes,string) not being used anywhere in the contract.

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

@Amxx
Copy link
Collaborator

Amxx commented Jun 14, 2022

Thank you @ZumZoom

Do have you measured the gas savings? If so, can you share the numbers?

@Amxx Amxx added this to the 4.8 milestone Jun 14, 2022
@ZumZoom
Copy link
Contributor Author

ZumZoom commented Jun 15, 2022

Here are gas reports from relevant tests.

TLDR: -54 gas on call, -2814 gas on deploy

Master

·-----------------------------------------------------|-------------|-----------------------------·
|                Solc version: 0.8.13                 ·  Runs: 200  ·  Block limit: 10000000 gas  │
······················································|·············|······························
|  Methods                                                                                        │
····························|·························|·············|···············|··············
|  Contract                 ·  Method                 ·  Avg        ·  # calls      ·  usd (avg)  │
····························|·························|·············|···············|··············
|  AddressImpl              ·  functionCall           ·      29880  ·            2  ·          -  │
····························|·························|·············|···············|··············
|  Deployments                                        ·             ·  % of limit   ·             │
······················································|·············|···············|··············
|  AddressImpl                                        ·     725017  ·        7.3 %  ·          -  │
·-----------------------------------------------------|-------------|---------------|-------------·

PR

·-----------------------------------------------------|-------------|-----------------------------·
|                Solc version: 0.8.13                 ·  Runs: 200  ·  Block limit: 10000000 gas  │
······················································|·············|······························
|  Methods                                                                                        │
····························|·························|·············|···············|··············
|  Contract                 ·  Method                 ·  Avg        ·  # calls      ·  usd (avg)  │
····························|·························|·············|···············|··············
|  AddressImpl              ·  functionCall           ·      29826  ·            2  ·          -  │
····························|·························|·············|···············|··············
|  Deployments                                        ·             ·  % of limit   ·             │
······················································|·············|···············|··············
|  AddressImpl                                        ·     722203  ·        7.2 %  ·          -  │
·-----------------------------------------------------|-------------|---------------|-------------·

@Amxx
Copy link
Collaborator

Amxx commented Jun 16, 2022

@ZumZoom Thank for these number. That is great !

@Amxx Amxx merged commit cb3f2ab into OpenZeppelin:master Jun 16, 2022
@Amxx Amxx mentioned this pull request Jun 16, 2022
@ZumZoom ZumZoom deleted the feature/optimize-functionCall branch June 16, 2022 13:21
ronhuafeng added a commit to ronhuafeng/openzeppelin-contracts that referenced this pull request Sep 9, 2022
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.

None yet

2 participants