foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feature(forge): fast gas profile analysis with graph

Open Syzygy106 opened this issue 3 weeks ago • 2 comments

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.

Image

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

  1. 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
  2. Special attention should be paid to operations that reference other smart contracts and make external calls.
  3. 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

Syzygy106 avatar Dec 02 '25 12:12 Syzygy106

@grandizzy , do you think that's not usefull? 😔

Syzygy106 avatar Dec 02 '25 15:12 Syzygy106

@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

grandizzy avatar Dec 03 '25 05:12 grandizzy