From cbb7cc20f824fd96279a0c14eb5d0a2187347955 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Tue, 13 Nov 2018 22:09:28 +0800 Subject: core: vm: Optimize evm (#13) * core: vm: add an EVM benchmark * core: vm: optimize stack allocation and instruction for calculating 2^n * Add DEXONBet bench --- core/vm/stack.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'core/vm/stack.go') diff --git a/core/vm/stack.go b/core/vm/stack.go index 4c1b9e803..14b1c289b 100644 --- a/core/vm/stack.go +++ b/core/vm/stack.go @@ -19,8 +19,15 @@ package vm import ( "fmt" "math/big" + "sync" ) +var stackPool = sync.Pool{ + New: func() interface{} { + return &Stack{data: make([]*big.Int, 0, 1024)} + }, +} + // Stack is an object for basic stack operations. Items popped to the stack are // expected to be changed and modified. stack does not take care of adding newly // initialised objects. @@ -29,7 +36,13 @@ type Stack struct { } func newstack() *Stack { - return &Stack{data: make([]*big.Int, 0, 1024)} + stack := stackPool.Get().(*Stack) + stack.data = stack.data[:0] + return stack +} + +func recyclestack(stack *Stack) { + stackPool.Put(stack) } // Data returns the underlying big.Int array. -- cgit