Skip to content

state: Cache repeated and negative account lookups#1583

Open
ywy2090 wants to merge 1 commit into
ipsilon:masterfrom
ywy2090:state-account-lookup-cache
Open

state: Cache repeated and negative account lookups#1583
ywy2090 wants to merge 1 commit into
ipsilon:masterfrom
ywy2090:state-account-lookup-cache

Conversation

@ywy2090

@ywy2090 ywy2090 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This resolves the TODO in State::find().

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. 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_map references) and is invalidated on the account erase in rollback().

Lookups of non-existent accounts (e.g. BALANCE/EXTCODESIZE of an empty address, repeated in a loop) previously hit the initial StateView on 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.

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 chfast left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed "If we want to cache non-existent account we need a proper flag for it.".

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.

2 participants