Skip to content

Address.functionCall internal call stack simplification#3468

Merged
Amxx merged 1 commit into
OpenZeppelin:masterfrom
ZumZoom:feature/optimize-functionCall
Jun 16, 2022
Merged

Address.functionCall internal call stack simplification#3468
Amxx merged 1 commit into
OpenZeppelin:masterfrom
ZumZoom:feature/optimize-functionCall

Conversation

@ZumZoom
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
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.

2 participants