state: Cache repeated and negative account lookups#1583
Open
ywy2090 wants to merge 1 commit into
Open
Conversation
Host callbacks look up the same account repeatedly: SLOAD/SSTORE perform two Host callbacks per instruction (access_storage followed by get_storage/set_storage), each doing a full hash-map lookup of the same address. Add a single-entry cache of the last successful lookup so the second callback only compares the address. The cached pointer is stable (unordered_map references) and is invalidated on account erase in rollback(). Lookups of non-existent accounts (e.g. BALANCE/EXTCODESIZE of an empty address) previously hit the initial StateView on every query. Cache the negative results in a set; insert() removes the entry when the account comes into existence. This resolves the TODO in State::find().
chfast
requested changes
Jul 13, 2026
chfast
left a comment
Member
There was a problem hiding this comment.
You missed "If we want to cache non-existent account we need a proper flag for it.".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This resolves the TODO in
State::find().Host callbacks look up the same account repeatedly: SLOAD/SSTORE perform two Host callbacks per instruction (
access_storagefollowed byget_storage/set_storage), each doing a full hash-map lookup of the same address. This adds a single-entry cache of the last successful lookup so the second callback only compares the address. The cached pointer is stable (unordered_mapreferences) and is invalidated on the account erase inrollback().Lookups of non-existent accounts (e.g. BALANCE/EXTCODESIZE of an empty address, repeated in a loop) previously hit the initial
StateViewon every query — with a real database backend each of those is a repeated trie/DB query. Cache the negative results in a set;insert()removes the entry when the account comes into existence.