Create a JIT
link: #542
What is wrong?
There are some actual optimizations that we could do at the EVM level with respect to doing JIT compilation.
How can it be fixed
There are operations that we can optimize at runtime like the following (inspired by release notes here.
- Replace sequence of
[SWAP1 LT]with[GT]-same with[SWAP1 GT] -> [LT] - Replace sequence of
[SWAP1 ADD]withADDbecause it's communicative.
These replacements need to be specially written to consume the equivalent gas of what they are replacing. Special care will also need to be taken to ensure that trace output isn't changed so that we can still do vm traces without exposing the underlying optimizations.
@pipermerriam I was thinking about this issue and thought that it was enough to replace the bytecode with the optimized replacements, before execution.
-
Here, in the following snippet of code, we could just place the optimizations before this
for loophttps://github.com/ethereum/py-evm/blob/d82b10ae361cde6abbac62f171fcea7809c4e3cf/eth/vm/computation.py#L571-L585 so as to change thecomputation code. -
To preserve the
gas, we could manually adjust thegas consumedwhen we are replacing theSWAP LTbyGT, etc. -
We could maintain a
list of indexes of the optimized bytecodewhere the code has been changed. While logging in thefor loopwe could check if we are at thatoptimized index, and hence adjust thelogat that particular position.
Is this approach ok?
@Bhargavasomu since this is going to be highly experimental and the implementation will need to be benchmarked against the existing implementation to verify it does indeed speed up processing I don't think I can comment on architecture until I've seen the implementation...