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

Turn on IR optimizer #332

Open
guidanoli opened this issue Dec 10, 2024 · 1 comment
Open

Turn on IR optimizer #332

guidanoli opened this issue Dec 10, 2024 · 1 comment
Labels
T-feature Type: feature

Comments

@guidanoli
Copy link
Collaborator

📚 Context

The Solidity compiler comes with an IR optimized that is turned off by default.
This optimizer can improve gas costs of function calls and contract size.
After doing a quick experiment with Via-IR, I've observed significant reductions on both metrics.
Here are some functions with significant gas cost improvements (median discrepancy):

  • ApplicationFactory.newApplication: -20.5%
  • SelfHostedApplicationFactory.deployContracts: -9.1%
  • Application.validateOutput: -9.7%
  • Application.executeOutput: -2.6%

✔️ Solution

Turn Via-IR on foundry.toml and hardhat.config.ts.

@guidanoli guidanoli added the T-feature Type: feature label Dec 10, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Rollups Unit Dec 10, 2024
@guidanoli
Copy link
Collaborator Author

Gas report diff

Contract Function Min Avg Max
Application -223176 (-20.76%)
Application executeOutput -2060 (-2.47%) -2664 (-2.35%) -3874 (-1.16%)
Application getConsensus 9 (2.62%) 9 (2.62%) 9 (2.62%)
Application getTemplateHash 25 (10.25%) 25 (10.25%) 25 (10.25%)
Application migrateToConsensus 89 (0.37%) 85 (0.31%) 79 (0.26%)
Application owner 86 (22.87%) 86 (8.25%) 86 (3.62%)
Application renounceOwnership -52 (-0.22%) -52 (-0.22%) -52 (-0.22%)
Application transferOwnership 69 (0.29%) 54 (0.21%) 13 (0.05%)
Application validateOutput 259 (24.16%) -1559 (-9.03%) -1736 (-7.22%)
Application validateOutputHash -206 (-28.14%) -2024 (-12.40%) -2207 (-9.31%)
Application wasOutputExecuted 13 (2.49%) 13 (0.52%) 13 (0.52%)
ApplicationFactory -243859 (-18.89%)
ApplicationFactory calculateApplicationAddress -3057 (-20.65%) -3057 (-20.65%) -3057 (-20.65%)
ApplicationFactory newApplication(address,address,bytes32) -206854 (-20.60%) -206855 (-20.59%) -206854 (-20.58%)
ApplicationFactory newApplication(address,address,bytes32,bytes32) -207016 (-20.59%) -69255 (-0.02%) 206269 (0.02%)
Authority -36136 (-12.38%)
Authority getEpochLength 3 (1.23%) 3 (1.23%) 3 (1.23%)
Authority owner -51 (-13.42%) -51 (-4.87%) -51 (-2.14%)
Authority renounceOwnership -141 (-0.61%) -141 (-0.61%) -141 (-0.61%)
Authority submitClaim -182 (-0.76%) -227 (-0.59%) -297 (-0.58%)
Authority transferOwnership -173 (-0.72%) -192 (-0.76%) -245 (-0.85%)
Authority wasClaimAccepted -127 (-18.43%) -127 (-7.45%) -127 (-4.72%)
AuthorityFactory -53987 (-10.17%)
AuthorityFactory calculateAuthorityAddress -655 (-12.93%) -655 (-12.93%) -655 (-12.93%)
AuthorityFactory newAuthority(address,uint256) -162 (-0.30%) -11155 (-8.74%) -33159 (-12.11%)
AuthorityFactory newAuthority(address,uint256,bytes32) -195 (-0.35%) 5 (0.00%) 33521 (0.00%)
ERC1155BatchPortal -45137 (-12.20%)
ERC1155BatchPortal depositBatchERC1155Token -397 (-1.32%) 2009 (0.16%) 46445 (0.62%)
ERC1155BatchPortalTest -433977 (-10.55%)
ERC1155BatchPortalTest encodePayload -313 (-5.80%) -1275 (-3.01%) -2320 (-2.76%)
ERC1155SinglePortal -50207 (-15.85%)
ERC1155SinglePortal depositSingleERC1155Token -433 (-1.60%) -615 (-1.41%) -883 (-1.21%)
ERC1155SinglePortal getInputBox 22 (13.17%) 22 (13.17%) 22 (13.17%)
ERC20Portal -40258 (-15.00%)
ERC20Portal depositERC20Tokens -231 (-0.90%) -390 (-1.09%) -846 (-1.35%)
ERC20Portal getInputBox 19 (11.38%) 19 (11.38%) 19 (11.38%)
ERC721Portal -46535 (-15.13%)
ERC721Portal depositERC721Token -402 (-1.50%) -683 (-1.57%) -1095 (-1.52%)
ERC721Portal getInputBox 22 (13.17%) 22 (13.17%) 22 (13.17%)
EtherPortal -30587 (-12.88%)
EtherPortal depositEther -74 (-0.29%) -139 (-0.24%) -185 (-0.30%)
EtherPortal getInputBox 19 (11.38%) 19 (11.38%) 19 (11.38%)
EtherReceiver -13130 (-11.44%)
EtherReceiver balanceOf -88 (-18.53%) -88 (-5.97%) -88 (-3.56%)
ExternalLibMerkle32 -112721 (-29.27%)
ExternalLibMerkle32 merkleRoot 38 (4.78%) -2370 (-12.80%) -67038 (-14.60%)
ExternalLibMerkle32 merkleRootAfterReplacement -191 (-27.88%) -639 (-17.99%) -7964 (-13.20%)
ExternalLibMerkle32 siblings 207 (22.12%) -579 (-6.43%) -63768 (-12.03%)
InputBox -41639 (-15.13%)
InputBox addInput -205 (-0.37%) -182 (-0.30%) 393463 (0.61%)
InputBox getInputHash -86 (-11.01%) -86 (-11.01%) -86 (-11.01%)
InputBox getNumberOfInputs -83 (-15.72%) -83 (-15.29%) -83 (-3.28%)
Quorum 3532603 (74.09%)
Quorum getEpochLength 68 (27.53%) 68 (27.53%) 68 (27.53%)
Quorum isValidatorInFavorOf -240 (-23.81%) -241 (-21.65%) -240 (-7.98%)
Quorum numOfValidators -16 (-7.08%) -16 (-7.08%) -16 (-7.08%)
Quorum numOfValidatorsInFavorOf -88 (-11.03%) -88 (-8.83%) -88 (-3.15%)
Quorum submitClaim -6 (-0.02%) -218 (-0.42%) -341 (-0.35%)
Quorum validatorById -116 (-23.20%) -116 (-21.93%) -116 (-4.64%)
Quorum validatorId -115 (-21.82%) -116 (-21.01%) -115 (-4.55%)
Quorum wasClaimAccepted -70 (-9.92%) -68 (-4.65%) -70 (-2.59%)
QuorumFactory -125031 (-16.76%)
QuorumFactory calculateQuorumAddress -1305 (-16.58%) -1154 (-8.92%) -1071 (-5.83%)
QuorumFactory newQuorum(address[],uint256) -206 (-0.37%) -42143 (-5.25%) -63937 (-2.44%)
QuorumFactory newQuorum(address[],uint256,bytes32) -239 (-0.42%) 242 (0.00%) 58317 (0.01%)
SafeERC20Transfer -58541 (-25.75%)
SafeERC20Transfer safeTransfer -836 (-19.47%) -936 (-6.19%) -1192 (-3.48%)
SelfHostedApplicationFactory 13070 (4.56%)
SelfHostedApplicationFactory calculateAddresses -3896 (-14.72%) -3896 (-14.72%) -3896 (-14.72%)
SelfHostedApplicationFactory deployContracts -332 (-0.57%) -68759 (-16.18%) -240445 (-18.99%)
SelfHostedApplicationFactory getApplicationFactory 10 (4.46%) 10 (4.46%) 10 (4.46%)
SelfHostedApplicationFactory getAuthorityFactory 16 (9.47%) 16 (9.47%) 16 (9.47%)
SimpleBatchERC1155 -166369 (-7.17%)
SimpleBatchERC1155 balanceOf -143 (-22.45%) -143 (-10.97%) -143 (-5.42%)
SimpleBatchERC1155 safeBatchTransferFrom -66 (-0.03%) -66 (-0.03%) -66 (-0.03%)
SimpleBatchERC1155 setApprovalForAll -51 (-0.11%) -51 (-0.11%) -51 (-0.11%)
SimpleERC20 -27852 (-5.02%)
SimpleERC20 approve -390 (-1.48%) -389 (-0.86%) -390 (-0.84%)
SimpleERC20 balanceOf -21 (-3.74%) -21 (-1.71%) -21 (-0.82%)
SimpleERC20 transfer -355 (-0.69%) -355 (-0.69%) -355 (-0.69%)
SimpleERC721 -212951 (-21.24%)
SimpleERC721 approve -333 (-0.68%) -330 (-0.68%) -333 (-0.68%)
SimpleERC721 ownerOf -1 (-0.17%) -1 (-0.17%) -1 (-0.04%)
SimpleERC721 safeTransferFrom -922 (-1.54%) -922 (-1.54%) -922 (-1.54%)
SimpleSingleERC1155 -159905 (-15.07%)
SimpleSingleERC1155 balanceOf -143 (-22.45%) -143 (-10.97%) -143 (-5.42%)
SimpleSingleERC1155 safeTransferFrom -221 (-0.41%) -221 (-0.41%) -221 (-0.41%)
SimpleSingleERC1155 setApprovalForAll -51 (-0.11%) -51 (-0.11%) -51 (-0.11%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant