feature(forge): fast gas profile analysis with graph
Component
Forge
Describe the feature you would like
Motivation
When entering a new project, it's often useful to analyze the gas profile of a contract and various scenarios of its operation. Sometimes you want to understand which specific logical part of a scenario consumes the most resources.
Foundry already has --gas-report and --flamegraph, but they don't provide a detailed assessment of where exactly in the scenario heavy operations occur.
A visual approach for initial analysis of heavy operations in a scenario would be convenient, in my opinion. By looking at a chart and visually identifying all high-load spots, you can easily separate unexpected costs from planned ones.
For example, you could use a coordinate system where the x-axis is the Solidity/Vyper source line number, and the y-axis is the gas cost amount. Then you could plot 2 graphs on this axis - a graph of instantaneous gas costs and a graph of cumulative gas costs. This would allow quick analysis of gas consumption patterns in a scenario, literally by glancing at it. When unexpected costs are discovered, you can navigate to and examine the source code of that logic part that is the cause.
Solution
I propose introducing a --gas-profile flag in forge test to implement this functionality. I think PcSourceMapper and CallTraceStep in revm_inspectors::tracing::types could be useful for the implementation.
Special Attention
- I think if the idea succeeds, a simple VSCode extension could be written that would allow navigation to the problem area by clicking on the chart
- Special attention should be paid to operations that reference other smart contracts and make external calls.
- I would like to discuss this idea in detail with the community, so please share your ideas. I think we can implement this feature together
Additional context
No response
@grandizzy , do you think that's not usefull? 😔
@Syzygy106 thanks for your ticket, I think it's nice to have but needs to be scrutinized with community, so maybe ask in TG and get reactions from there too. marked as low until we get more opinions about and since there are other things to tackle for now. thank you