Is there information regarding the size limits of a mapping managed by a smart contract on moonbeam?
Can a mapping grow to a million entries? What are the consequences (cost, efficiency, others) if a contract manipulates such a big mapping?
From my knowledge, there is no limit to a mapping size. It can easily grow to a million entries. Keep in mind that the mapping is not iterable, hence its scalability. Contrary to an array, you access it using its key.
The main limit I could see would be block gas limit (60M here), related to the type of edit you’re making to the state. Each new entry in a mapping incurs a storage cost, which is relatively expensive in Solidity. Still, on Moonbeam I consider it’s cheap. Also, re-writing a pair value is cheaper than registering a new one.
Hope it helps
Thanks for your reaction @MAR1 !
I indeed want to be able to iterate over the mapping (for backup or in case of required migration) , and I maintain an array with all the keys of the mapping.
IIUC, even if the mapping has millions of entries:
- adding one entry doesn’t get more expensive (storage cost of a new entry doesn’t grow in relation with the mapping size)
- accessing one random entry doesn’t get slower
The mapping will be append only. Seems cost per stored byte is 366 gas, that I need to convert to GLMR (which I didn’t do yet as I don’t seem to find the conversion rate of gas to GLMR…)