I am trying to find a source on what the difference is between optimized and unoptimized code. My main question is what the unoptimized compiler does, especially in the sense of calling the SSTORE
opcode.
Let's say I have this:
contract A{
uint8 mem1;
uint8 mem2;
function store(uint8 store1, uint8 store2){
mem1=store1;
mem2=store2;
}
}
When I would compile this in a "dumb" way I would call SSTORE
twice to store both variables. However, to optimize this I would allocate the first 8 bits of an uint256
(SSTORE
always stores uint256
's) to mem1
and the second 8 bits to mem2
. Like this, I only have to call SSTORE
once per transaction. However, this might result in a slight overhead in other code the contract may have since we need to extract the right bits. SSTORE
takes 20k gas when saving a non-zero value, so optimizing this code saves 20k gas.
Does the unoptimized compiler, when compiling above code, call SSTORE
twice or once? I know I can check this myself by compiling and reading the OPCODES
, but I'd like to find a source on what both compilers should do.