reth
reth copied to clipboard
perf(trie): optimize TrieNodeIter by skipping redundant seek
trafficstars
Fixes: #15329
Avoids the unnecessary hashed_cursor.seek(key) operation within TrieNodeIter that could occur if the immediately preceding hashed_cursor.next() call had already positioned the cursor at the key. It checks the last_next_result field (tracking the key and value from the last next() call) against the intended seek_key. If the keys match, the redundant seek() is skipped and the cached result is used. Added the last_next_result field to store the needed state, it is cleared during seek operations.
Also updated the assertion for visited keys in the existing test_trie_node_iter unit test to reflect the new optimised sequence of cursor operations (omitting the redundant seek).