Gas consumpion report on single function
profiler console output
Sometimes it could be excruciating to find out most
hungry lines of solidity code.
It could happen because of wrong loop condition or overflow, and unclear.
We've thought that Solidity profiler is missing part for the Ethereum development eco-system and decided to implement working prototype during hackathon using wide known tools.
We've forked solidity coverage. And after did following fixes:
- Bulk renaming to save compatibility with the original project.
- Extend code coverage event with
- Patch event procession and report generation step, to nicely render it with
Istanbulcode coverage utils that is a part of solidity coverage
To demonstrate how profiler works we take our fork of ecsol project. On that fork we apply has gas optimization that was purposed by Vitalik. So, we were really curious to know the details of our gas optimization.
To get solidity profiler output on sample project do the following:
First, you need the following global dependencies installed:
npm install -g truffle npm install -g ganache-cli
After clone repositories and perform
npm i and
npm run profiler
mkdir solidity-profiler-demo cd solidity-profiler-demo git clone https://github.com/k06a/solidity-profiler cd solidity-profiler npm i cd ../ git clone -b feature/solidity-profiler https://github.com/1Address/ecsol cd ecsol npm i npm run profiler
Discover report file in
Challenges we run into
We've made a couple of mistakes in our implementation:
- We've calculated gas consumption by nested calls in the wrong way.
- We don't calculate correctly gas consumption by event emission
- We have a lot of things to improve in visualization in the report
At first, we've decided to extend
Istanbul output to add Gas consumption by a line near the line entrance amount.
Our hackathon solution is just a proof of concept and we think that can improve it in the following way:
- Display min/max/avg/median gas consumption for each line
- Split complex lines to multiple lines with indentation
- Make a lot of other improvements and fixes on a long way to the production use ;-)