*: do not use WriteArray
for frequently used items
`WriteArray` involves reflection, it makes sense to optimize serialization of transactions and application logs which are serialized constantly. Adding case in a type switch in `WriteArray` is not an option because we don't want new dependencies for `io` package. ``` name old time/op new time/op delta AppExecResult_EncodeBinary-8 852ns ± 3% 656ns ± 2% -22.94% (p=0.000 n=10+9) name old alloc/op new alloc/op delta AppExecResult_EncodeBinary-8 448B ± 0% 376B ± 0% -16.07% (p=0.000 n=10+10) name old allocs/op new allocs/op delta AppExecResult_EncodeBinary-8 7.00 ± 0% 5.00 ± 0% -28.57% (p=0.000 n=10+10) ``` ``` name old time/op new time/op delta Transaction_Bytes-8 1.29µs ± 3% 0.76µs ± 5% -41.52% (p=0.000 n=9+10) name old alloc/op new alloc/op delta Transaction_Bytes-8 1.21kB ± 0% 1.01kB ± 0% -16.56% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Transaction_Bytes-8 12.0 ± 0% 7.0 ± 0% -41.67% (p=0.000 n=10+10) ``` Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
43ee671f36
commit
291a29af1e
4 changed files with 52 additions and 4 deletions
|
@ -13,6 +13,31 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func BenchmarkAppExecResult_EncodeBinary(b *testing.B) {
|
||||
aer := &AppExecResult{
|
||||
Container: random.Uint256(),
|
||||
Execution: Execution{
|
||||
Trigger: trigger.Application,
|
||||
VMState: vm.HaltState,
|
||||
GasConsumed: 12345,
|
||||
Stack: []stackitem.Item{},
|
||||
Events: []NotificationEvent{{
|
||||
ScriptHash: random.Uint160(),
|
||||
Name: "Event",
|
||||
Item: stackitem.NewArray([]stackitem.Item{stackitem.NewBool(true)}),
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
w := io.NewBufBinWriter()
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
w.Reset()
|
||||
aer.EncodeBinary(w.BinWriter)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeDecodeNotificationEvent(t *testing.T) {
|
||||
event := &NotificationEvent{
|
||||
ScriptHash: random.Uint160(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue