Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prune wasm codes proposal #1455

Closed
wants to merge 18 commits into from
25 changes: 25 additions & 0 deletions x/wasm/keeper/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/stretchr/testify/require"

"github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
wasmvm "github.com/CosmWasm/wasmvm"
)

// BenchmarkVerification benchmarks secp256k1 verification which is 1000 gas based on cpu time.
Expand Down Expand Up @@ -100,3 +102,26 @@ func BenchmarkCompilation(b *testing.B) {
})
}
}

// Calculate the time it takes to prune about 100k wasm codes
func BenchmarkPruningWasmCodes(b *testing.B) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start to get some numbers.
This runs with a mem db, tiny contracts and no duplicate instances. I can imagine disk IO can have some impact here but let's add another DB to compare them

mockWasmVM := wasmtesting.MockWasmer{
RemoveCodeFn: func(checksum wasmvm.Checksum) error {
return nil
},
}
wasmtesting.MakeInstantiable(&mockWasmVM)
ctx, keepers := CreateTestInput(b, false, AvailableCapabilities, WithWasmEngine(&mockWasmVM))

for i := 0; i < 100000; i++ {
contract := StoreRandomContract(b, ctx, keepers, &mockWasmVM)
if i%10 == 0 {
keepers.ContractKeeper.PinCode(ctx, contract.CodeID)
}
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
keepers.WasmKeeper.PruneWasmCodes(ctx, 100000)
}
}
2 changes: 1 addition & 1 deletion x/wasm/keeper/wasmtesting/mock_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (m *MockWasmer) Unpin(checksum wasmvm.Checksum) error {
}

func (m *MockWasmer) RemoveCode(checksum wasmvm.Checksum) error {
if m.UnpinFn == nil {
if m.RemoveCodeFn == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

panic("not supposed to be called!")
}
return m.RemoveCodeFn(checksum)
Expand Down