fix(lib/runtime/storage): improve NextKeys
time complexity
#3958
Labels
C-complex
Complex changes across multiple modules. Possibly will require additional research.
P-critical
this must be fixed immediately or contributors or users will be severely impacted.
S-sync-westend
related to particular network syncing.
T-refactor
this issue/pr covers refactoring of existing code.
Description
When the runtime requests the next key under an ongoing transaction we should not use
t.state.Entries()
, this method will go through the entire in-memory trie inserting each key and value in a map to be used to search the next key in lexicographic order. This is not optimal because the trie tends to grow sot.state.Entries()
is O(n).Outside of ongoing transaction the same method searches in the in-memory trie directly which is more efficient since you don't need to search the entire trie but just the path for the next key in lex order
The motivation is explained here: #3950 (comment).
The text was updated successfully, but these errors were encountered: