euler-xyz / euler-price-oracle

Euler Price Oracles, a library of immutable oracle adapters and components

Home Page:https://docs.euler.finance/euler-price-oracle/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimization: low-level calls for hot paths

totomanov opened this issue · comments

  • measure gas savings

@hoytech
I replaced EulerRouter and ChainlinkAdapter's calls with low-level staticcall. Could not see gas savings in tests, even after controlling for foundry's "make everything one tx" mechanics by wrapping the call in the test with gasleft and measuring it myself + cooling down warm slots.

It turns out we pay the 2600 gas either way. Looking at evm.codes, both STATICCALL and EXTCODESIZE will charge 2600 gas on cold and 100 gas on warm access.

A Solidity higher-level external call inserts EXTCODESIZE then STATICALL: 2600 + 100 = 2700 gas for access.
A Yul low-level staticall inserts STATICCALL: 2600 gas for access. Saving 100 gas IMO is not worth it, and in practice we pay more runtime gas for the additional logic that the low-level call incurs. So it actually charges more gas.