I know that the EVM wants to charge for reading from slots, and even more for writing to those slots. That all makes sense.
My question is, whether the EVM is smart enough to store in memory the temporary values, before writing it to storage when the transaction commits (ends without reverting).
Meaning, I would expect to be paying the same gas whether I write to a slot once, or whether I write to it, read from it, write to it, read from it multiple times. The EVM should mark that slot as "used", not "used N times".
Is this how EVM works? I understand that if I read from the slot first, and then write to it, then I might incur two gas fees, but if I write to it and read and write multiple times then it shouldn't charge me every time, right?
The reason I ask is because I want to make a "MicroMapping" of uint16
values, and I want to know if I have to write my own manual batching, or whether I can write multiple times to the same slot (calling the same setMicroMapping(index, key, value)
) and keeping the code clean.
Any advice?