-
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
Best in class Gas Reporting #1795
Comments
thanks for this write up. in order to support this, we need some kind of https://github.com/foundry-rs/foundry/blob/master/forge/src/gas_report.rs to track this a bit more fine-grained we'd need a custom visualizing this is then just additional work. ref #1737 |
Ref #137 |
Closing in favor of #7761 for flamegraphs + #8222 for lifting of required information for flamegraphs Related tickets:
|
Component
Forge
Describe the feature you would like
Make it easy for the Foundry users to identify & optimize gas usage of their contracts.
Currently, the gas is reported as a single number next to the test cases or function names.
This doesn't help new users understand what's taking up all the gas in the transaction. The lack of insights pushes users to adopt questionable hacks (e.g.
unchecked
) vs optimizing the heavy operations (likeSSTORE
).Here are a few ideas on how to improve gas reporting visuals:
Opcodes Histogram
Group every opcode executed in the transaction by the opcode itself (maybe
SSTORE
/SLOAD
need flags like hot/cold) and plot the total cumulative gas consumption. Feels like this would be the easiest to implement as it only requiresdebug_traceTransaction
and a hashmap.The disadvantage here is that it's not obvious how to find the expensive operations in the contract without having a good idea of how Solidity & EVM work.
Flame Graph
This is a screenshot from Tenderly's gas profiler tool. It gives a good idea of which functions are contributing the most to gas consumption. Ideally, the lowest level should show heavy opcodes.
This probably requires an untrivial amount of work connecting gas usage to (obfuscated) function names.
Export Systrace
Systrace is commonly used to debug the performance of large & complicated systems. Its ecosystem has a bunch of tools for processing and visualizations, so if we could export a compatible JSON file we could get a lot of this functionality for free.
This is very advanced, but also very hard to use for a regular user.
Compare Before & After
A typical flow optimizing gas is to make a change and compare reports between previous and current runs. This is error-prone and fragile. We could store gas profiles in a temporary location and show if the numbers improved or got worse vs the last run.
With Opcodes Histogram or Flame Graph, we could use some color to highlight the differences in a very visual (and motivating) way.
Tenderly Integration
Tenderly has decent visualizations and tools, but getting it to work with hardhat is a lot of pain. Thinking of an ideal DX here, maybe passing a flag to
forge
command could send the tx (along with everything else needed, like source code) to Tenderly and print out a URL to view the trace.Additional context
No response
The text was updated successfully, but these errors were encountered: