py-evm icon indicating copy to clipboard operation
py-evm copied to clipboard

Create a JIT

Open pipermerriam opened this issue 7 years ago • 2 comments

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] with ADD because 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 avatar Apr 17 '18 17:04 pipermerriam

@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 loop https://github.com/ethereum/py-evm/blob/d82b10ae361cde6abbac62f171fcea7809c4e3cf/eth/vm/computation.py#L571-L585 so as to change the computation code.

  • To preserve the gas, we could manually adjust the gas consumed when we are replacing the SWAP LT by GT, etc.

  • We could maintain a list of indexes of the optimized bytecode where the code has been changed. While logging in the for loop we could check if we are at that optimized index, and hence adjust the log at that particular position.

Is this approach ok?

Bhargavasomu avatar Dec 22 '18 12:12 Bhargavasomu

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

pipermerriam avatar Jan 04 '19 23:01 pipermerriam