ethereum / fe

Emerging smart contract language for the Ethereum blockchain.
https://fe-lang.org
Other
1.61k stars 187 forks source link

Consider using Egg to build a YUL IR optimizer #340

Open brockelmore opened 3 years ago

brockelmore commented 3 years ago

What is wrong?

Currently, all optimization is done inside solc. While solc does okay optimization, their focus is diverted to a number of different needs. One way Fe can get broader adoption is via better gas optimizations than solc at the YUL IR step. Therefore, given that this is written in rust, one option is a library called egg. Here is a good overview video. Currently, the order of optimizations is more or less fixed. E-graphs can find the optimum arrangement for all codebases without requiring excessive amounts of memory and so could produce better output from compilers.

It supports custom cost functions for the optimization, so given the nature of the EVM and its EXPLICIT costs, this cost function would be a relatively easy lift from that perspective. This doesn't require removing the solc backend, it at the very least could offer a better optimization than what exists in solc. It also can still go through the solc optimizer as well, so you should still get proven optimizations from there.

hrkrshnn commented 3 years ago

What sort of optimizations can egg do that IR optimizer currently can't do? It seems that the expression simplifier in Yul should cover the things mentioned about egg.