-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
What we need to do
Right now every single instruction calls gas_cost() and creates a new state struct. Since all instructions cost 1 gas anyway, we can batch this and only check gas every 16 instructions or so.
Expected outcome
15-20% speedup by eliminating overhead on every instruction
Code example
Current (slow):
# This happens for EVERY instruction
gas_cost = Instructions.gas_cost(opcode) # Always returns 1
deduct_gas = %{state_ | gas: state.gas - gas_cost}Better (fast):
# Only check gas every 16 instructions
instruction_count = instruction_count + 1
if rem(instruction_count, 16) == 0 do
new_state = %{state_ | gas: state.gas - 16}
if new_state.gas < 0, do: {:out_of_gas, new_state}
endThis eliminates the pattern matching and struct creation on 15 out of every 16 instructions.
Reactions are currently unavailable