gas-optimizations
gas-optimizations copied to clipboard
List of smart contract optimizations in solidity
I believe the example for this optimization is not completely correct. Immutable should be used when the state variable is assigned in the constructor. If it is directly assigned in...
Should add a section on this to https://github.com/kadenzipfel/gas-optimizations/blob/main/gas-saving-patterns/short-circuiting.md with this to leave the reader with a fully optimized statement e.g. use ``` if (condition) { if (anotherCondition) { ... }...
for technical gas saving patterns, e.g. https://github.com/KadenZipfel/gas-optimizations/blob/main/gas-saving-patterns/optimal-comparison-operator.md, in which the pattern works because of a solidity compilation gotcha, the mechanism in which gas is saved should be better detailed, e.g....
Each gas optimization should have this information: - further knowledge links to understand why that change improves gas usage - `forge snapshot` to compare A/B testing. How much gas are...
some things that can be added: - use selfbalance opcode instead of address(this).balance - use iszero opcode instead of if(x) - https://twitter.com/clemlak/status/1521973218864771073?s=20&t=Bw97nieWjOAs4O2x2Kr8Tg - etc
in general, do while loops are cheaper than for loops. as long as the loop is must run at least once, do while is preferred over for loops
we should make sure we have both: - clear examples, and - before and after gas benchmarks for every gas saving pattern