scilla
scilla copied to clipboard
New builtin for field map garbage collection
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}
}
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.
Related issue: #900