Gas Profiling #8323
-
ComponentForge Describe the feature you would likeHey everyone, first off thank you for the work on foundry so far, I've been enjoying working with it. I'd like to ask about gas metering though - what dev workflows do people use/recommend for profiling functions at the moment, and what's the current general plans for future work on this aspect. Here's the methods I'm presently aware of:
In order to address the shortcomings with approach 4 it seems to me that it requires fairly extensive work: some sort of cheatcode that can be used to tell forge to run the subsequent code as if it were a new transaction, giving it fresh state to work with. I'm not remotely familiar with forge internal working so no idea how practical attempting that even is, alas. So to recap:
Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Any progress on this |
Beta Was this translation helpful? Give feedback.
-
Any Answer for this... it is important for developers... |
Beta Was this translation helpful? Give feedback.
-
We've since added the option to run tests in isolation: https://book.getfoundry.sh/reference/cli/forge/test?highlight=isolate#forge-test, this greatly improves the accuracy of tracking gas.
Other improvements like those developed in https://github.com/marktoda/forge-gas-snapshot/ can potentially be upstreamed We also support the Converting this ticket into a discussion as there are no direct actionable items. |
Beta Was this translation helpful? Give feedback.
-
We've recently added new cheatcodes to capture gas usage over arbitrary sections: #8952. This also includes internal gas tracking and it most similar to You can read more how to use them here: https://book.getfoundry.sh/forge/gas-section-snapshots To determine the trade-offs between the different ways of capturing snapshots see: https://book.getfoundry.sh/forge/gas-tracking |
Beta Was this translation helpful? Give feedback.
We've recently added new cheatcodes to capture gas usage over arbitrary sections: #8952. This also includes internal gas tracking and it most similar to
gasleft()
.You can read more how to use them here: https://book.getfoundry.sh/forge/gas-section-snapshots
To determine the trade-offs between the different ways of capturing snapshots see: https://book.getfoundry.sh/forge/gas-tracking