62 - Arrays - Gas Costs
Gas Costs of push
and pop
: Increasing the length of a storage array by calling push()
has constant gas costs because storage is zero-initialised, while decreasing the length by calling pop()
has a cost that depends on the “size” of the element being removed.
If that element is an array, it can be very costly, because it includes explicitly clearing the removed elements similar to calling delete on them.
push()
&pop()
- Push -> Constant Cost
- Pop -> Depends on Element Size
- Pop Array Element -> Expensive -> Delete Element