forked from cerc-io/laconicd-deprecated
evm: add benchmark for deep context stack (#627)
* Problem: deep context stack efficienty is not benchmarked Closes: #626 Solution: - add a benchmark to demonstrate an extremely inefficiency in deep context stack * Update x/evm/keeper/benchmark_test.go * prefix storage is irrelevant * add comment to state_transition.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
bcdb982886
commit
78c8ceb244
@ -12,6 +12,7 @@ import (
|
||||
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
ethermint "github.com/tharsis/ethermint/types"
|
||||
"github.com/tharsis/ethermint/x/evm/keeper"
|
||||
"github.com/tharsis/ethermint/x/evm/types"
|
||||
)
|
||||
|
||||
@ -95,3 +96,40 @@ func BenchmarkTokenMint(b *testing.B) {
|
||||
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func DoBenchmarkDeepContextStack(b *testing.B, depth int) {
|
||||
begin := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
||||
end := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
||||
|
||||
suite := KeeperTestSuite{}
|
||||
suite.DoSetupTest(b)
|
||||
|
||||
transientKey := suite.app.GetTKey(types.TransientKey)
|
||||
|
||||
var stack keeper.ContextStack
|
||||
stack.Reset(suite.ctx)
|
||||
|
||||
for i := 0; i < depth; i++ {
|
||||
stack.Snapshot()
|
||||
|
||||
store := stack.CurrentContext().TransientStore(transientKey)
|
||||
store.Set(begin, []byte("value"))
|
||||
}
|
||||
|
||||
store := stack.CurrentContext().TransientStore(transientKey)
|
||||
for i := 0; i < b.N; i++ {
|
||||
store.Iterator(begin, end)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDeepContextStack1(b *testing.B) {
|
||||
DoBenchmarkDeepContextStack(b, 1)
|
||||
}
|
||||
|
||||
func BenchmarkDeepContextStack10(b *testing.B) {
|
||||
DoBenchmarkDeepContextStack(b, 10)
|
||||
}
|
||||
|
||||
func BenchmarkDeepContextStack13(b *testing.B) {
|
||||
DoBenchmarkDeepContextStack(b, 13)
|
||||
}
|
||||
|
@ -199,6 +199,8 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT
|
||||
}
|
||||
|
||||
// flatten the cache contexts to improve efficiency of following db operations
|
||||
// the reason is some operations under deep context stack is extremely slow,
|
||||
// refer to `benchmark_test.go:BenchmarkDeepContextStack13`.
|
||||
k.ctxStack.CommitToRevision(revision)
|
||||
|
||||
k.IncreaseTxIndexTransient()
|
||||
|
Loading…
Reference in New Issue
Block a user