aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/jit.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-08-07 05:06:47 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-08-07 18:52:23 +0800
commitac697326a6045eaa760b159e4bda37c57be61cbf (patch)
tree9f26ac6308b7ae0b9d0a6daab772aae796ee7a54 /core/vm/jit.go
parent184e9ae9a81df2db6381e18d3daa035d913ae341 (diff)
downloadgo-tangerine-ac697326a6045eaa760b159e4bda37c57be61cbf.tar.gz
go-tangerine-ac697326a6045eaa760b159e4bda37c57be61cbf.tar.zst
go-tangerine-ac697326a6045eaa760b159e4bda37c57be61cbf.zip
core/vm: reduced big int allocations
Reduced big int allocation by making stack items modifiable. Instead of adding items such as `common.Big0` to the stack, `new(big.Int)` is added instead. One must expect that any item that is added to the stack might change.
Diffstat (limited to 'core/vm/jit.go')
-rw-r--r--core/vm/jit.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/core/vm/jit.go b/core/vm/jit.go
index c66630ae8..d5c2d7830 100644
--- a/core/vm/jit.go
+++ b/core/vm/jit.go
@@ -404,9 +404,10 @@ func jitCalculateGasAndSize(env Environment, context *Context, caller ContextRef
mSize, mStart := stack.data[stack.len()-2], stack.data[stack.len()-1]
+ add := new(big.Int)
gas.Add(gas, params.LogGas)
- gas.Add(gas, new(big.Int).Mul(big.NewInt(int64(n)), params.LogTopicGas))
- gas.Add(gas, new(big.Int).Mul(mSize, params.LogDataGas))
+ gas.Add(gas, add.Mul(big.NewInt(int64(n)), params.LogTopicGas))
+ gas.Add(gas, add.Mul(mSize, params.LogDataGas))
newMemSize = calcMemSize(mStart, mSize)
case EXP:
@@ -496,18 +497,20 @@ func jitCalculateGasAndSize(env Environment, context *Context, caller ContextRef
newMemSize.Mul(newMemSizeWords, u256(32))
if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 {
+ // be careful reusing variables here when changing.
+ // The order has been optimised to reduce allocation
oldSize := toWordSize(big.NewInt(int64(mem.Len())))
pow := new(big.Int).Exp(oldSize, common.Big2, Zero)
- linCoef := new(big.Int).Mul(oldSize, params.MemoryGas)
+ linCoef := oldSize.Mul(oldSize, params.MemoryGas)
quadCoef := new(big.Int).Div(pow, params.QuadCoeffDiv)
oldTotalFee := new(big.Int).Add(linCoef, quadCoef)
pow.Exp(newMemSizeWords, common.Big2, Zero)
- linCoef = new(big.Int).Mul(newMemSizeWords, params.MemoryGas)
- quadCoef = new(big.Int).Div(pow, params.QuadCoeffDiv)
- newTotalFee := new(big.Int).Add(linCoef, quadCoef)
+ linCoef = linCoef.Mul(newMemSizeWords, params.MemoryGas)
+ quadCoef = quadCoef.Div(pow, params.QuadCoeffDiv)
+ newTotalFee := linCoef.Add(linCoef, quadCoef)
- fee := new(big.Int).Sub(newTotalFee, oldTotalFee)
+ fee := newTotalFee.Sub(newTotalFee, oldTotalFee)
gas.Add(gas, fee)
}
}