diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-13 22:09:28 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:18 +0800 |
commit | cbb7cc20f824fd96279a0c14eb5d0a2187347955 (patch) | |
tree | 13a9847a758f8b5802b89cbfec96b5d2ef7329ce /core/vm/stack.go | |
parent | 1df4ff9e24539a7a99c245fed3a47e8198f26de9 (diff) | |
download | go-tangerine-cbb7cc20f824fd96279a0c14eb5d0a2187347955.tar.gz go-tangerine-cbb7cc20f824fd96279a0c14eb5d0a2187347955.tar.zst go-tangerine-cbb7cc20f824fd96279a0c14eb5d0a2187347955.zip |
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
Diffstat (limited to 'core/vm/stack.go')
-rw-r--r-- | core/vm/stack.go | 15 |
1 files changed, 14 insertions, 1 deletions
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. |