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.
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.
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.