In general, it seems as though mappings generally result in cheaper operations. What about when the number of elements are fixed (say, 20K) and setting the elements only ever occur once?

Would a mapping still prove cheaper? What if iteration is necessary?


Deep down, an array is a mapping with range-bound keys. The most expensive aspect is the SSTORE operations and SLOAD operations which are the same in both cases.

An array has additional steps (operations, so gas) to check that row is not out of range.

A dynamic array is significantly more expensive because each push overwrites the length and range checks read from storage rather than compiled bytecode, i.e. additional SSTORE and SLOAD.

Hope it helps

  • Amazing. Thanks. – Leeren Mar 25 at 6:31
  • did you mean SLOAD by the way? And could you expand on what you meant by them being the same in both cases? – Leeren Mar 25 at 21:59
  • @leeren Yes, Good catch.Thanks. – Rob Hitchens Mar 25 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.