I'm interested/worried about the size of the State Trie over time

Lets suppose I have a contract with two vars:

uint myNumber;
uint[] myArray;

As far as I understand, If I change the value of "myNumber", a new copy of it will be added to the State Tree (thus taking more HDD space), which is fine and needed because if we ever want to rebuild data history from a previous state we need it (and maybe rewrite-performance reasons).

But, what about if I push (increase length and set value) a new uint into "myArray". Will the whole array be copied to the new State Tree? Or only the new "uint" will be added to the tree and the array will be rebuilt by iterating over the State Tree/DB?

I'm not asking about mappings because I assume they are just spread independent variables in the memory. Are arrays the same kind of "magic"?



Well... looks weird that I'm answering myself in 10minutes, but while writing the question I realised my last phrase could happen. And then googled it...

According to Solidity documentation:

Due to their unpredictable size, mapping and dynamically-sized array types use a sha3 computation to find the starting position of the value or the array data. These starting positions are always full stack slots.

So I guess that kinda answers my question :/. As I understand, each [i]/position of my array will be an independent word in EVM's memory space, so whenever a position one is added, only the change on array's "length" word and my new "word" will change/be replicated in the state trie.

So basically arrays are basically as mappings with a length variable where the key is the position

Am I right?

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.