🍔 add some notes on saving gas in solidity

This commit is contained in:
bt3gl 2022-09-21 18:13:24 -07:00 committed by GitHub
parent 3b076fdc73
commit 1e56456d4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,12 +6,17 @@
- *In DeFi, any gas saving is an edge. Below are some notes on tricks we use.*
- Note that in Solidity, the maximum size of a contract is restricted to 24 KB by [EIP 170](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md).
---
## Function names
- In Ninja we brute force hashes of function names to find those that starts `0000`, so this can save around 50 gas
- TBA: show the code
- brute force hashes of function names to find those that starts `0000`, so this can save around 50 gas
- avoid calls to other contracts
---
@ -47,6 +52,7 @@ Constant values can sometimes be cheaper than immutable values:
### Mappings are cheaper than Arrays
- avoid dynamically sized arrays
- An array is not stored sequentially in memory but as a mapping.
- You can pack Arrays but not Mappings.
- Its cheaper to use arrays if you are using smaller elements like `uint8` which can be packed together.