You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Speed up gas metering by batching instead of per-instruction #35
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 instructiongas_cost=Instructions.gas_cost(opcode)# Always returns 1deduct_gas=%{state_|gas: state.gas-gas_cost}
Better (fast):
# Only check gas every 16 instructionsinstruction_count=instruction_count+1ifrem(instruction_count,16)==0donew_state=%{state_|gas: state.gas-16}ifnew_state.gas<0,do: {:out_of_gas,new_state}end
This eliminates the pattern matching and struct creation on 15 out of every 16 instructions.
Activity