-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: expand snapshot functionality #2056
Comments
Also might complicate #1980 because of command arg flattening, see #1980 (comment) Edit: Another consideration is that snapshot files are nameable right now, so it's possible to have e.g. a One final consideration is that there's been some talk of merging snapshot/gas report but I can't find the convo Edit 2: Given all above points an alternative suggestion (no strong preference, just wanted to add context to the issue):
|
Some other ideas for gas snapshots specifically can be found in #137 |
Would be great to upstream the core ideas from here: https://github.com/marktoda/forge-gas-snapshot as used here: https://github.com/Uniswap/v4-core/tree/main/.forge-snapshots |
Considering the growing popularity of https://github.com/marktoda/forge-gas-snapshot (used in Uniswap V4, Balancer V3, Euler V2) I've proposed to add native functionality for its feature set. There is rough consensus on moving ahead with the following changes:
Some of my concerns:
@mds1 curious on your thoughts about this proposal |
Thanks for proposing this @zerosnacks - I'm (obviously) very in favor of upstreaming this into Foundry. For a bit more context, the primary reason we prefer this type of snapshotting at Uniswap is to get maximal granularity, allowing us to check how the gas of specific flows change over time in version control. Generally I think the approach makes sense. A couple ideas -
|
Component
Forge
Describe the feature you would like
Inspired by this twitter convo
Feature Spec
Right now
forge snapshot
saves the gas usage of each test to a file called.gas-snapshot
. This is useful for things like gas golfing, or ensuring that a changeset does not increase gas costs. Similar functionality can be applied to other properties of a codebase.I propose modifying
forge snapshot
as follows:Instead of being a single command, it now has subcommands to snapshot various things:
forge snapshot gas
behaves likeforge snapshot
currently does.forge snapshot size
is equivalent to runningforge build --sizes
and saving the output table.forge snapshot <fieldName>
would let you snapshot any solc field name supported byforge inspect
. By default this would snapshot the field for all contracts in thesrc
directoryInstead of saving to the project root, these commands save a file called
<property>.snapshot
to a folder named something likesnapshot
,snap
, orss
. Examples:forge snapshot gas
results insnapshot/gas.snapshot
forge snapshot storage-layout
results insnapshot/storage-layout.snapshot
The
--check
,--diff
, and--snap
options should be supported for each subcommand and behave the same as they do now. Some subcommands may have additional options, such as:--include-fuzz-tests
for gas snapshots, or always including fuzz tests and just specifying the seed here--asc
and--desc
should be supported for ones where sorting makes sense, such as gas and size snapshots.Open questions
forge inspect
supports multiple variants for a given property. For example, you can see thatforge inspect MyContract storage
,forge inspect MyContract storageLayout
,forge inspect MyContract storage-layout
, andforge inspect MyContract storage_layout
all print the storage layout. We'd want to standardize on which name we use for the output files. My suggestion is using the JSON field name output by solc, which for this example I believe isstorage
.Additional context
No response
The text was updated successfully, but these errors were encountered: