You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In many places we only need the key when iterating over storage. However, we currently load both key and value into the Wasm space. This performs the following unnecessary operations:
v := iter.Value(), i.e. the actual read on the database
Copying the data from Go to Rust
Copy key and value into a single buffer to write it to Wasm (encode_sections)
Decompose key and value into separate vectors in Wasm (decode_sections2)
The following use cases would benefit from a key-only iterator by consuming less ressources:
Deletations such as Map::clear
All usages of Prefix::keys and Prefix::keys_raw
Iterators that only aim to return the last existing key for incrementing
An implementation can be broken down as follows:
Provide db_next_key and db_next_value that operate on the exact same iterator ID as db_next but only return one value. They can be implemented via Storage::next for now.
Add Storage::next_key and Storage::next_value to the backend storage trait and implement in GoStorage by utilizing GoStorage::next
Add GoIter::next_key and GoIter::next_value and corresponsding FFI calls
Make import db_next_key and db_next_value usable in contracts
next/next_key/next_value all inrement the iterator exactly once. For each call you can decide which return value you want to use. This way they can all share the same iterator ID system.
The text was updated successfully, but these errors were encountered:
The list above is not necessarily ordered. Since we have #1748 already in 1.3, it makes sense to move from contract to chain, one step at a time. We can always fall back on the next implementation that returns both key and value.
In many places we only need the key when iterating over storage. However, we currently load both key and value into the Wasm space. This performs the following unnecessary operations:
v := iter.Value()
, i.e. the actual read on the databaseencode_sections
)decode_sections2
)The following use cases would benefit from a key-only iterator by consuming less ressources:
Map::clear
Prefix::keys
andPrefix::keys_raw
An implementation can be broken down as follows:
db_next_key
anddb_next_value
that operate on the exact same iterator ID asdb_next
but only return one value. They can be implemented viaStorage::next
for now.Storage::next_key
andStorage::next_value
to the backend storage trait and implement inGoStorage
by utilizingGoStorage::next
GoIter::next_key
andGoIter::next_value
and corresponsding FFI callsdb_next_key
anddb_next_value
usable in contractsnext
/next_key
/next_value
all inrement the iterator exactly once. For each call you can decide which return value you want to use. This way they can all share the same iterator ID system.The text was updated successfully, but these errors were encountered: