core: don't recalculate witness script hash
We know it already, but with current loading code VM will hash it once more. It doesn't help a lot and still it costs nothing to avoid this overhead. name old time/op new time/op delta VerifyWitness-8 93.4µs ± 3% 92.7µs ± 2% ~ (p=0.353 n=10+10) name old alloc/op new alloc/op delta VerifyWitness-8 3.43kB ± 0% 3.40kB ± 0% -0.70% (p=0.000 n=9+9) name old allocs/op new allocs/op delta VerifyWitness-8 67.0 ± 0% 66.0 ± 0% -1.49% (p=0.000 n=10+10)
This commit is contained in:
parent
e41fc2fd1b
commit
39f874d03f
2 changed files with 25 additions and 1 deletions
24
pkg/core/bench_test.go
Normal file
24
pkg/core/bench_test.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkVerifyWitness(t *testing.B) {
|
||||||
|
bc := newTestChain(t)
|
||||||
|
acc, err := wallet.NewAccount()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
tx := bc.newTestTx(acc.Contract.ScriptHash(), []byte{byte(opcode.PUSH1)})
|
||||||
|
require.NoError(t, acc.SignTx(netmode.UnitTestNet, tx))
|
||||||
|
|
||||||
|
t.ResetTimer()
|
||||||
|
for n := 0; n < t.N; n++ {
|
||||||
|
_ = bc.VerifyWitness(tx.Signers[0].Account, tx, &tx.Scripts[0], 100000000)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1837,7 +1837,7 @@ func (bc *Blockchain) InitVerificationVM(v *vm.VM, getContract func(util.Uint160
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%w: %v", ErrInvalidVerification, err)
|
return fmt.Errorf("%w: %v", ErrInvalidVerification, err)
|
||||||
}
|
}
|
||||||
v.LoadScriptWithFlags(witness.VerificationScript, callflag.ReadOnly)
|
v.LoadScriptWithHash(witness.VerificationScript, hash, callflag.ReadOnly)
|
||||||
} else {
|
} else {
|
||||||
cs, err := getContract(hash)
|
cs, err := getContract(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue