scilla icon indicating copy to clipboard operation
scilla copied to clipboard

New builtin for field map garbage collection

Open anton-trunov opened this issue 4 years ago • 2 comments

Some contracts tend to accumulate lots of nested empty maps and when the semantics of the contract permits we should have a mechanism to clean the empty maps. @vaivaswatha has suggested to implement this as a new builtin because it's easier to do this at the C++ level.

Example:

A map like this
{
"key1" -> {"key1a" -> 42}
"key2" -> {}
"key3" -> {}
...
"key42" -> {}
}

often times can be simplified to

{
"key1" -> {"key1a" -> 42}
}

anton-trunov avatar Apr 05 '21 09:04 anton-trunov

A common scenario is when in a nested map, all keys of a nested map are deleted (and we have an empty map), but the corresponding key in the outer map (that now holds an empty inner map as its value) lives on.

A builtin can be provided to prune such keys in an outer map that have empty map values.

Implementation: It looks to me that the best way to do this is to have a direct call, via IPC, to the blockchain code that will scan the leveldb database and perform this operation.

Edit: This comment turned out to be redundant given @anton-trunov 's update to the Issue description. I'll let it stay on though.

vaivaswatha avatar Apr 05 '21 09:04 vaivaswatha

Related issue: #900

anton-trunov avatar Aug 18 '22 13:08 anton-trunov