
# Gas and codesize implications of the muldiv functions

## Gas test results

At arbos-forge release `5e956b7586b924778ff3b6117afb9153d47a18ce` (1.4.4):

|            Name           |  Gas cost |
|---------------------------|-----------|
| Ruint                     | 8673      |
| Muldiv Uniswap            | 12674     |
| Widening then truncating  | 587751    |

## 9lives and storage

Anecdotally, the order of costs for the various muldiv functions look like this, when we
used it in the 9lives repo for our DPPM code:

|            Name           |  Codesize cost |
|---------------------------|----------------|
| Widening then truncating  | Cheap          |
| Muldiv Uniswap            | Moderate       |
| Ruint                     | Expensive      |

## Takeaway

So, you should make a decision based on the context of what you're working on when your
main focus is codesize, since there's undoubtably some reuse of code here. Do some
experimentation yourself. Ruint works with 64 bit words, then branches to pick different
algorithms. 9lives uses muldiv for fee taking operations, with numbers of either 1e6,
1000, and 1e12. You need to enable ruint with `ruint-enabled`. It might be more
appropriate to use ruint if you're already using U256 from alloy, given the amount of code
reuse presumably.
