You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
inline
summary
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 (like SSTORE).
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 requires debug_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:
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: