morpho-org / morpho-utils

Repository gathering useful libraries and contracts.
GNU Affero General Public License v3.0
65 stars 1 forks source link

Optimize `abs` #104

Closed QGarchery closed 1 year ago

QGarchery commented 1 year ago

It gains an additional 26 gas compared to the target branch on the abs function

github-actions[bot] commented 1 year ago

Changes to gas cost

Generated at commit: 8ca4c2171f028b3bf6ac3dd265fa521d5ada026b, compared to commit: 37a6abbbb81d6bafff6351c9223b9079645e30f4

๐Ÿงพ Summary (20% most significant diffs)

Contract Method Avg (+/-) %
MathRef contract log2Naive -43,904 โœ… -98.68%

Full diff report ๐Ÿ‘‡
| Contract | Deployment Cost (+/-) | Method | Min (+/-) | % | Avg (+/-) | % | Median (+/-) | % | Max (+/-) | % | # Calls (+/-) | |:-|-:|:-|-:|-:|-:|-:|-:|-:|-:|-:|-:| | **MathRef contract** | 238,081 (0) | _abs_
_log2Dichotomy_
_log2Naive_
_max_
_min_
_safeAbs_
_zeroFloorSub_ | 440 (+108)
4,742 (+1)
586 (-43,904)
376 (-10)
408 (+10)
422 (+80)
416 (+53) | **+32.53%**
**+0.02%**
**-98.68%**
**-2.59%**
**+2.51%**
**+23.39%**
**+14.60%** | 440 (+108)
4,742 (+1)
586 (-43,904)
376 (-10)
408 (+10)
422 (+80)
416 (+53) | **+32.53%**
**+0.02%**
**-98.68%**
**-2.59%**
**+2.51%**
**+23.39%**
**+14.60%** | 440 (+108)
4,742 (+1)
586 (-43,904)
376 (-10)
408 (+10)
422 (+80)
416 (+53) | **+32.53%**
**+0.02%**
**-98.68%**
**-2.59%**
**+2.51%**
**+23.39%**
**+14.60%** | 440 (+108)
4,742 (+1)
586 (-43,904)
376 (-10)
408 (+10)
422 (+80)
416 (+53) | **+32.53%**
**+0.02%**
**-98.68%**
**-2.59%**
**+2.51%**
**+23.39%**
**+14.60%** | 1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0) | | **MathMock contract** | 135,783 (-2,400) | _abs_ | 367 (-26) | **-6.62%** | 367 (-26) | **-6.62%** | 367 (-26) | **-6.62%** | 367 (-26) | **-6.62%** | 1 (0) | | **WadRayMathRef contract** | 327,168 (0) | _rayToWad_ | 432 (-14) | **-3.14%** | 432 (-14) | **-3.14%** | 432 (-14) | **-3.14%** | 432 (-14) | **-3.14%** | 1 (0) |