mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
core: only pull out state once
This commit is contained in:
parent
ee68abeaa1
commit
b6417f2efe
3 changed files with 17 additions and 31 deletions
|
|
@ -18,6 +18,7 @@ package vm
|
|||
|
||||
import (
|
||||
"math"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -77,29 +78,19 @@ func TestLoopInterrupt(t *testing.T) {
|
|||
|
||||
func BenchmarkInterpreter(b *testing.B) {
|
||||
var (
|
||||
evm = NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{})
|
||||
startGas uint64 = 30_000_000
|
||||
statedb, _ = state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
|
||||
evm = NewEVM(BlockContext{BlockNumber: big.NewInt(1), Time: 1, Random: &common.Hash{}}, statedb, params.MergedTestChainConfig, Config{})
|
||||
startGas uint64 = 100_000_000
|
||||
value = uint256.NewInt(0)
|
||||
stack = newstack()
|
||||
mem = NewMemory()
|
||||
contract = NewContract(common.Address{}, common.Address{}, value, startGas, nil)
|
||||
)
|
||||
contract.Code = common.Hex2Bytes(loopInterruptTests[0])
|
||||
stack.push(uint256.NewInt(123))
|
||||
stack.push(uint256.NewInt(123))
|
||||
gasSStoreEIP3529 = makeGasSStoreFunc(params.SstoreClearsScheduleRefundEIP3529)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
evm.interpreter.Run(contract, []byte{}, false)
|
||||
gasSStoreEIP3529(evm, contract, stack, mem, 1234)
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkInterpreter-14 14613990 79.01 ns/op 32 B/op 2 allocs/op
|
||||
|
||||
func BenchmarkDup(b *testing.B) {
|
||||
stack := newstack()
|
||||
stack.push(uint256.NewInt(1234))
|
||||
stack.push(uint256.NewInt(4321))
|
||||
for range b.N {
|
||||
for range 1_000_000 {
|
||||
//stack.dup(1)
|
||||
stack.dup1()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkDup-14 38 31579698 ns/op 188685761 B/op 2 allocs/op
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
|
|||
var (
|
||||
y, x = stack.Back(1), stack.peek()
|
||||
slot = common.Hash(x.Bytes32())
|
||||
current = evm.StateDB.GetState(contract.Address(), slot)
|
||||
current, original = evm.StateDB.GetStateAndCommittedState(contract.Address(), slot)
|
||||
cost = uint64(0)
|
||||
)
|
||||
// Check slot presence in the access list
|
||||
|
|
@ -52,7 +52,6 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
|
|||
// return params.SloadGasEIP2200, nil
|
||||
return cost + params.WarmStorageReadCostEIP2929, nil // SLOAD_GAS
|
||||
}
|
||||
original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
|
||||
if original == current {
|
||||
if original == (common.Hash{}) { // create slot (2.1.1)
|
||||
return cost + params.SstoreSetGasEIP2200, nil
|
||||
|
|
|
|||
|
|
@ -117,10 +117,6 @@ func (st *Stack) dup(n int) {
|
|||
st.push(&st.data[st.len()-n])
|
||||
}
|
||||
|
||||
func (st *Stack) dup1() {
|
||||
st.push(&st.data[st.len()-1])
|
||||
}
|
||||
|
||||
func (st *Stack) peek() *uint256.Int {
|
||||
return &st.data[st.len()-1]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue