Skip to content

Commit

Permalink
Problem: deep context stack efficienty is not benchmarked
Browse files Browse the repository at this point in the history
Closes: evmos#626

Solution:
- add a benchmark to demonstrate an extremely inefficiency in deep
  context stack
  • Loading branch information
yihuang committed Oct 6, 2021
1 parent 202bc5f commit c523d81
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions x/evm/keeper/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/ethereum/go-ethereum/common"

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"
)

Expand Down Expand Up @@ -95,3 +97,46 @@ 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("transient_evm")

var stack keeper.ContextStack
stack.Reset(suite.ctx)

for i := 0; i < depth; i++ {
stack.Snapshot()

store := prefix.NewStore(
stack.CurrentContext().TransientStore(transientKey),
types.KeyPrefixTransientTxLogs,
)
store.Set(begin, []byte("value"))
}

store := prefix.NewStore(
stack.CurrentContext().TransientStore(transientKey),
types.KeyPrefixTransientTxLogs,
)
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)
}

0 comments on commit c523d81

Please sign in to comment.