-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Append overlay refactor proposal #13940
base: master
Are you sure you want to change the base?
Conversation
Please don't review yet (will change design a bit to be closest to paritytech/polkadot-sdk#30) |
- append always set an append item - move data only between two consecutive append - store size and offset at current depth
So this applies to all appendable storage structus? Otherwise we should probably add a test to check that this solution has a low memory footprint on deeply nested reverts (as expected). |
yes all storage item containing a value. But as I did comment a bit in the code, using a same key value with sp_io::set and later with sp_io::append is really bad and no sensible runtime should allow it. (if you got a value that is encoded Vec of length 3 so starting with a compact, call to append with a 4 byte encoded vec will change the current byte length to 4 and append the content, then reading will get nothing sensible.
So yes in practice it could be in a different key space, but that is basically what transient storage does (need to copy final value in some finalize to a standard state value though).
yes, but we cannot ensure it. In my next change, the storage will make this usecase better (with paritytech/polkadot-sdk#30, if only writes followed by a single read (root calculation), then we will not have anymore the costy resize each time the number of element Compact change in size (or a single one)). |
I think I did align with paritytech/polkadot-sdk#30 , should be reviewable (requires more test, especially since most test access on every transaction change and thus render the data). |
I really think storing big value is a mistake so at some point paged list really make sense. |
Ah right. So it depends on the use-case. For |
For events we should use transient storage (only write root of an event trie in state and still index data in an external db), but this is probably not here soon, so yes short term this is more pragmatic. |
I went through a bit of fuzzing and fix a few issue, think this would be good to review now. |
The CI pipeline was cancelled due to failure one of the required jobs. |
This branch propose to avoid clones in append by storing offset and size in previous overlay depth.
That way on rollback we can just truncate and change size of existing value.
To avoid copy it also means that :
The modify mechanism is not needed anymore.
This branch lacks testing and break some existing genericity (bit of duplicated code), but good to have to check direction.
Generally I am not sure if it is worth or we just should favor differents directions (transients blob storage for instance), as the current append mechanism is a bit tricky (having a variable length in first position means we sometime need to insert in front of a vector).