Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trie: improve the node iterator seek operation #22470

Merged
merged 2 commits into from
Apr 21, 2021

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Mar 9, 2021

This PR improves the efficiency of the nodeIterator seek operation.
Previously, the seek operation used the nextChild to iterate across the fullnode chldren, resolving each as it traversed towards the seek position.

Example:

marker: 01ee4cbd12051867841e785a715f770a635da089ff75b19eff5e6f719963e83f
trie.resolveHash resolve path 
INFO [03-09|14:20:27.177] Resuming state snapshot generation       root="349972…b86d77" at="01ee4c…63e83f" accounts=7 slots=0 storage=278.00B elapsed=1.875ms eta=263ms
trie.resolveHash resolve path 00
trie.resolveHash resolve path 0000
trie.resolveHash resolve path 0001
trie.resolveHash resolve path 000104
trie.resolveHash resolve path 000108
trie.resolveHash resolve path 00010e
trie.resolveHash resolve path 0002
trie.resolveHash resolve path 000206
trie.resolveHash resolve path 00020600
marker []: 0260c4f779bc30181efdd3639b6db85257cf2ee898aa2ffa6fd3ab675cf2fb0a

The marker it starts on is 00 01 0e .... . To find it, it resolves 00, 0000(!), 0001, 000104(!), 000108 (!) and 00010e. The ones marked with (!) are siblings that should not have to be resolved.
Since we resolve the fullnode parent (at 0001), it should be possible for the iterator to go directly to the 00010e child without resolving the sibling children.

So it does 9 lookups. After this PR, it does only 6: 00, 0001, 00010e, 0002, 000206, 00020600.:

marker: 01ee4cbd12051867841e785a715f770a635da089ff75b19eff5e6f719963e83f
trie.resolveHash resolve path 
INFO [03-09|16:27:20.719] Resuming state snapshot generation       root="349972…b86d77" at="01ee4c…63e83f" accounts=7 slots=0 storage=278.00B elapsed="704.754µs" eta=131ms
trie.resolveHash resolve path 00
trie.resolveHash resolve path 0001
trie.resolveHash resolve path 00010e
trie.resolveHash resolve path 0002
trie.resolveHash resolve path 000206
trie.resolveHash resolve path 00020600
marker []: 0260c4f779bc30181efdd3639b6db85257cf2ee898aa2ffa6fd3ab675cf2fb0a

trie/iterator.go Outdated Show resolved Hide resolved
@fjl fjl merged commit 4b783c0 into ethereum:master Apr 21, 2021
@fjl fjl removed the status:triage label Apr 21, 2021
@fjl fjl added this to the 1.10.3 milestone Apr 21, 2021
atif-konasl pushed a commit to frozeman/pandora-execution-engine that referenced this pull request Oct 15, 2021
This change improves the efficiency of the nodeIterator seek
operation. Previously, seek essentially ran the iterator forward
until it found the matching node. With this change, it skips
over fullnode children and avoids resolving them from the database.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants