Repository navigation
perf(test-forks): memoize per-fork gas costs - #3303
Merged
LouisTsai-Csie merged 2 commits intoAug 14, 2026
Merged
LouisTsai-Csie merged 2 commits into
LouisTsai-Csie merged 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## forks/amsterdam #3303 +/- ##
===================================================
- Coverage 93.53% 93.19% -0.35%
===================================================
Files 624 624
Lines 37074 37074
Branches 3394 3394
===================================================
- Hits 34679 34551 -128
- Misses 1645 1726 +81
- Partials 750 797 +47
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
LouisTsai-Csie
requested changes
Aug 7, 2026
LouisTsai-Csie
left a comment
Contributor
There was a problem hiding this comment.
Some comments on the new test cases: I'm unsure if they properly test cache behavior.
4 of 11 tasks
LouisTsai-Csie
marked this pull request as ready for review
August 14, 2026 07:53
LouisTsai-Csie
force-pushed
the
perf/memoize-fork-gas-costs
branch
from
August 14, 2026 08:11
a29c2f7 to
178c11d
Compare
LouisTsai-Csie
approved these changes
Aug 14, 2026
Contributor
|
Successfully created backport PR for |
LouisTsai-Csie
added a commit
that referenced
this pull request
Aug 14, 2026
2 tasks done
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.
Description
Fork.gas_costs()was recomputed on every call. Each EIP layer in the fork hierarchy implements it asreplace(super().gas_costs(), ...), so a single call on a late fork walks the whole chain and allocates oneGasCostsper layer: 16dataclasses.replacecalls for Amsterdam, at 787 us per call.The filler calls it in the inner loop of the benchmark gas searches (
transaction_intrinsic_cost_calculatorinside_binary_search_iterations),where it accounted for ~17% ofdataclasses.replacetime in a py-spy profile of a stateful fill.BaseForkMeta.__new__now wraps everygas_costsoverride in a per-fork cache, so thesuper()chain runs once per fork rather than once per call. Wrapping in the metaclass rather than at each of the 18 definition sites is what makes this work:Fork.gas_costs()resolves through the MROto the last EIP that overrode it, and only a cache on that override can return before the chain runs. It also means a new EIP cannot silently opt out.Each override keeps its own cache keyed on
cls, so a half-assembled value from the middle of asuper()chain can never be handed out as the final one, and no fork can serve another fork's value. The abstract declaration onBaseForkis left alone soabcstill reports it unimplemented.Sharing one object is safe because
GasCostsis a frozen dataclass whose every field is anint-- there is nothing a caller could mutate. TheMEMOIZED_FORK_METHODSdocstring states that contract for anything added later, and a unit test enforces it.Measured, per call:
End to end on
fill --fork=Prague tests/prague/eip7623_increase_calldata_cost/(1467 fixtures, single process, 3 runs each): 53.16 s -> 38.99 s,a 1.36x speedup.Output is unchanged:
GasCostsis byte-identical for all 35 forks, dumped and diffed against the unmodified base.Related Issues or PRs
N/A.
Checklist
ruff check,ruff format --checkandmypyare clean repo-wide (justis unavailable in thisenvironment; the 3 remaining mypy errors are the pre-existingrust_pyspec_glue/ethashimport stubs that--group optimizedsupplies).pytest packages/testing/srcis 1941 passed, 31 skipped, 19 xfailed, 2 xpassed.<type>(<area>): <title>