Skip to content

perf: stack-allocate PlainKey encoding in hot EVM state read path#107

Open
KENILSHAHH wants to merge 1 commit intomegaeth-labs:mainfrom
KENILSHAHH:kenil/perf/stack-allocate-plainkey
Open

perf: stack-allocate PlainKey encoding in hot EVM state read path#107
KENILSHAHH wants to merge 1 commit intomegaeth-labs:mainfrom
KENILSHAHH:kenil/perf/stack-allocate-plainkey

Conversation

@KENILSHAHH
Copy link

Summary

Stack-allocate PlainKey encoding in hot EVM state read path

  • Add PlainKey::encode_account() and PlainKey::encode_storage() returning
    fixed-size stack arrays ([u8; 20] and [u8; 52]) instead of heap-allocated Vec<u8>
  • Update the four hot-path callers in database.rs (basic_ref, storage_ref,
    bucket_id_for_account, bucket_id_for_slot) to use the new stack-allocating methods
  • Eliminate a heap allocation on every EVM state read during block execution

Account and storage key sizes are fixed by the Ethereum specification (20 and 52 bytes
respectively), making stack arrays the correct choice. The existing encode() -> Vec<u8>
is retained for the executor.rs use-site where an owned allocation is still required.

@KENILSHAHH KENILSHAHH requested a review from flyq as a code owner March 24, 2026 19:08
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.

1 participant