aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/stack.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-11-13 22:09:28 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:53 +0800
commitc1138b576524413f8d5755f77aaebd759d6317fc (patch)
treef237a6de9aea1d41a175a71a90a622312740e8c3 /core/vm/stack.go
parent16122f0041756465198c560d9a486f610efcc787 (diff)
downloaddexon-c1138b576524413f8d5755f77aaebd759d6317fc.tar
dexon-c1138b576524413f8d5755f77aaebd759d6317fc.tar.gz
dexon-c1138b576524413f8d5755f77aaebd759d6317fc.tar.bz2
dexon-c1138b576524413f8d5755f77aaebd759d6317fc.tar.lz
dexon-c1138b576524413f8d5755f77aaebd759d6317fc.tar.xz
dexon-c1138b576524413f8d5755f77aaebd759d6317fc.tar.zst
dexon-c1138b576524413f8d5755f77aaebd759d6317fc.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.go15
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.