core/vm: move nil-check out of the interpreter loop (#32068)

Moves the jumptable nil check our of the interpreter loop.
Benchmarks show a 2-10% improvement.
This commit is contained in:
Ömer Faruk Irmak 2025-07-07 11:01:29 +03:00 committed by GitHub
parent 063033834b
commit bdf47f4557
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -181,10 +181,11 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
} }
var ( var (
op OpCode // current opcode op OpCode // current opcode
mem = NewMemory() // bound memory jumpTable *JumpTable = in.table
stack = newstack() // local stack mem = NewMemory() // bound memory
callContext = &ScopeContext{ stack = newstack() // local stack
callContext = &ScopeContext{
Memory: mem, Memory: mem,
Stack: stack, Stack: stack,
Contract: contract, Contract: contract,
@ -227,6 +228,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
// explicit STOP, RETURN or SELFDESTRUCT is executed, an error occurred during // explicit STOP, RETURN or SELFDESTRUCT is executed, an error occurred during
// the execution of one of the operations or until the done flag is set by the // the execution of one of the operations or until the done flag is set by the
// parent context. // parent context.
_ = jumpTable[0] // nil-check the jumpTable out of the loop
for { for {
if debug { if debug {
// Capture pre-execution values for tracing. // Capture pre-execution values for tracing.
@ -247,7 +249,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
// Get the operation from the jump table and validate the stack to ensure there are // Get the operation from the jump table and validate the stack to ensure there are
// enough stack items available to perform the operation. // enough stack items available to perform the operation.
op = contract.GetOp(pc) op = contract.GetOp(pc)
operation := in.table[op] operation := jumpTable[op]
cost = operation.constantGas // For tracing cost = operation.constantGas // For tracing
// Validate stack // Validate stack
if sLen := stack.len(); sLen < operation.minStack { if sLen := stack.len(); sLen < operation.minStack {