reth icon indicating copy to clipboard operation
reth copied to clipboard

perf(trie): optimize TrieNodeIter by skipping redundant seek

Open 7suyash7 opened this issue 7 months ago • 0 comments
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).

7suyash7 avatar Apr 22 '25 08:04 7suyash7