Skip to content

Commit b99c4b9

Browse files
omerfirmakgballet
authored andcommitted
core/vm: move nil-check out of the interpreter loop (ethereum#32068)
Moves the jumptable nil check our of the interpreter loop. Benchmarks show a 2-10% improvement.
1 parent 1779d67 commit b99c4b9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

core/vm/interpreter.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,11 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
181181
}
182182

183183
var (
184-
op OpCode // current opcode
185-
mem = NewMemory() // bound memory
186-
stack = newstack() // local stack
187-
callContext = &ScopeContext{
184+
op OpCode // current opcode
185+
jumpTable *JumpTable = in.table
186+
mem = NewMemory() // bound memory
187+
stack = newstack() // local stack
188+
callContext = &ScopeContext{
188189
Memory: mem,
189190
Stack: stack,
190191
Contract: contract,
@@ -227,6 +228,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
227228
// explicit STOP, RETURN or SELFDESTRUCT is executed, an error occurred during
228229
// the execution of one of the operations or until the done flag is set by the
229230
// parent context.
231+
_ = jumpTable[0] // nil-check the jumpTable out of the loop
230232
for {
231233
if debug {
232234
// Capture pre-execution values for tracing.
@@ -247,7 +249,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
247249
// Get the operation from the jump table and validate the stack to ensure there are
248250
// enough stack items available to perform the operation.
249251
op = contract.GetOp(pc)
250-
operation := in.table[op]
252+
operation := jumpTable[op]
251253
cost = operation.constantGas // For tracing
252254
// Validate stack
253255
if sLen := stack.len(); sLen < operation.minStack {

0 commit comments

Comments
 (0)