Skip to content

feat(benchmarking): Optimize IteratingBytecode#2184

Merged
fselmo merged 5 commits intoethereum:forks/amsterdamfrom
marioevz:optimize-iterating-bytecode
Feb 11, 2026
Merged

feat(benchmarking): Optimize IteratingBytecode#2184
fselmo merged 5 commits intoethereum:forks/amsterdamfrom
marioevz:optimize-iterating-bytecode

Conversation

@marioevz
Copy link
Member

🗒️ Description

Focuses on optimizing the test generation in benchmarking, particularly test tests/benchmark/compute/instruction/test_account_query.py::test_account_query[fork_Osaka-blockchain_test_engine_x-value_sent_0-code_size_256-mem_size_32-access_warm_True-opcode_EXTCODECOPY-benchmark-gas-value_150M], which is the longest running test excluding t8n executions at 169.82s, by doing the following optimizations:

Cache Bytecode.keccak256

This method is heavily used by tests that compute the CREATE2 address to determine where a contract is going to be deployed.

This optimization simply caches the result of keccak inside a Bytecode object, and also makes compute_create2_address aware of the input potentially being a Bytecode to avoid converting to Bytes and wasting the optimization.

After optimization: 169.82s -> 60.18s

Cache Bytecode.gas_cost(fork)/Bytecode.refund(fork)

Another simple cache to return the previous known value when the functions are called with the same parameters. The cache holds a single item because we rarely call this function with multiple forks in a single instance.

After optimization: 60.18s -> 56.55s

CustomSizedContractFactory.created_contract_address Caching

Creates a dictionary cache inside of CustomSizedContractFactory to hold the calculated addresses of the different salts. The cache is not evicted, but it should be ok since the instance of CustomSizedContractFactory never makes it out of the test function, and the hash sizes are relatively small.

After optimization: 56.55s -> 22.54s

Access List Caching in test_account_query

Finally, test tests/benchmark/compute/instruction/test_account_query.py::test_account_query uses a dynamic access list to warm up addresses of the contracts to be used during the attack, and this is done using a callback, which is repeatedly called many times due to the binary search performed by IteratingBytecode to find the max amount of iterations given the gas limit of the test.

After optimization: 22.54s -> 9.31s

🔗 Related Issues or PRs

N/A.

✅ Checklist

  • All: Ran fast tox checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    uvx tox -e static
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Considered updating the online docs in the ./docs/ directory.
  • All: Set appropriate labels for the changes (only maintainers can apply labels).
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.
  • Tests: For PRs implementing a missed test case, update the post-mortem document to add an entry the list.
  • Ported Tests: All converted JSON/YML tests from ethereum/tests or tests/static have been assigned @ported_from marker.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@marioevz marioevz requested a review from fselmo February 10, 2026 23:19
@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.07%. Comparing base (658e388) to head (a891bb9).

Additional details and impacted files
@@               Coverage Diff                @@
##           forks/amsterdam    #2184   +/-   ##
================================================
  Coverage            86.07%   86.07%           
================================================
  Files                  599      599           
  Lines                39472    39472           
  Branches              3780     3780           
================================================
  Hits                 33977    33977           
  Misses                4862     4862           
  Partials               633      633           
Flag Coverage Δ
unittests 86.07% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fselmo fselmo merged commit 114eaf5 into ethereum:forks/amsterdam Feb 11, 2026
10 of 15 checks passed
RazorClient pushed a commit to RazorClient/execution-specs that referenced this pull request Feb 11, 2026
…thereum#2184)

* Separate first three secp256r1 vector topic files

* Extract another two topic files

* Three more topic separations

* Generalize infinity point topic, add test cases

* Additional grouping

* More sorting

* Final test cases sorted

* Delete original file

* Apply suggestions from code review

Co-authored-by: spencer <spencer.taylor-brown@ethereum.org>

* Small fixes

* Linting

---------

Co-authored-by: spencer <spencer.taylor-brown@ethereum.org>
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