-
Notifications
You must be signed in to change notification settings - Fork 31
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
Effectiveness of Address Format Change and Next Action #578
Comments
1. SummaryThis is a post about "8 Address Format" in comment. The relevant part of "8 Address Format" has been fixed by #298. We would like to compare [email protected] and [email protected] for the relevant part of "8 Address Format" and reflect the better correction. I measured Number of Executions and Microbenchmark as the judgment material. 2. Target Functions for ComparisonI measured the functions that seemed to have the greatest impact on execution time.
3. Number of Executions of Target FunctionsMeasuring methodWhen the following command is executed and a transaction is sent, the number of times string () is executed for one address is measured. I also measured the total number of executions of the target function when no transaction was sent (that is total number of execution per no tx block generation).
ResultsThe result of the number of executions per address is as follows.
The result of total number of execution per no tx block generation is For simplicity, it is assumed that all addresses are used for the first time this time. From the above result, the total number of executions of the target function per block generation is expressed by the following formula.
4. Microbenchmark of Target FunctionsExecution environmentDocker on M1 macbook pro Benchmark methodThe execution time was measured when the target function was executed once, 11 times and 56 times. From Number of Executions of Target Functions results, executing the target function 11 times and 56 times is performed to take into account the effect of the cache. See the "benchmark code" chapter in the appendix for the code and tools used for benchmarking. Results
The following results are obtained by summing up the results of executing 11 times and 56 times.
5. Discussion
The total number of executions of the target function per block generation is expressed by the following formula.
Ignore 69 times (total number of execution per no tx block generation), from the result of AccAddress.String() x (11 + 56), the execution time ratio of lbm-sdk and cosmos-sdk is about 4:5. there seems to be no big difference in execution time between lbm-sdk and cosmos-sdk. 6. AppendixBenchmark codego test -bench . -benchmem lbm_vs_cosmos_test.gopackage main
import (
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/require"
lbm_ed25519 "github.com/line/lbm-sdk/crypto/keys/ed25519"
lbm_types "github.com/line/lbm-sdk/types"
csms_ed25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
csms_types "github.com/cosmos/cosmos-sdk/types"
csms_bech32 "github.com/cosmos/cosmos-sdk/types/bech32"
)
func BenchmarkLbmAccAddressStringOneTime(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
acc := lbm_types.BytesToAccAddress(pk.Address())
str := string(acc)
b.StartTimer()
str2 := acc.String()
require.Equal(b, str, str2)
}
}
func BenchmarkLbmAccAddressString11Times(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
acc := lbm_types.BytesToAccAddress(pk.Address())
str := string(acc)
b.StartTimer()
for i := 0; i < 11; i++ {
str2 := acc.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkLbmAccAddressString56Times(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
acc := lbm_types.BytesToAccAddress(pk.Address())
str := string(acc)
b.StartTimer()
for i := 0; i < 56; i++ {
str2 := acc.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkLbmValAddressStringOneTime(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
val := lbm_types.BytesToValAddress(pk.Address())
str := string(val)
b.StartTimer()
str2 := val.String()
require.Equal(b, str, str2)
}
}
func BenchmarkLbmValAddressString11Times(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
val := lbm_types.BytesToValAddress(pk.Address())
str := string(val)
b.StartTimer()
for i := 0; i < 11; i++ {
str2 := val.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkLbmValAddressString56Times(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
val := lbm_types.BytesToValAddress(pk.Address())
str := string(val)
b.StartTimer()
for i := 0; i < 56; i++ {
str2 := val.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkLbmConsAddressStringOneTime(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
cons := lbm_types.BytesToConsAddress(pk.Address())
str := string(cons)
b.StartTimer()
str2 := cons.String()
require.Equal(b, str, str2)
}
}
func BenchmarkLbmConsAddressString11Times(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
cons := lbm_types.BytesToConsAddress(pk.Address())
str := string(cons)
b.StartTimer()
for i := 0; i < 11; i++ {
str2 := cons.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkLbmConsAddressString56Times(b *testing.B) {
pkBz := make([]byte, lbm_ed25519.PubKeySize)
pk := &lbm_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
cons := lbm_types.BytesToConsAddress(pk.Address())
str := string(cons)
b.StartTimer()
for i := 0; i < 56; i++ {
str2 := cons.String()
require.Equal(b, str, str2)
}
}
}
// ---------------------------------------------------------------------------------
func BenchmarkCsmsAccAddressStringOneTime(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
acc := csms_types.AccAddress(pk.Address())
bech32PrefixAccAddr := csms_types.GetConfig().GetBech32AccountAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixAccAddr, acc.Bytes())
require.NoError(b, err)
b.StartTimer()
str2 := acc.String()
require.Equal(b, str, str2)
}
}
func BenchmarkCsmsAccAddressString11Times(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
acc := csms_types.AccAddress(pk.Address())
bech32PrefixAccAddr := csms_types.GetConfig().GetBech32AccountAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixAccAddr, acc.Bytes())
require.NoError(b, err)
b.StartTimer()
for i := 0; i < 11; i++ {
str2 := acc.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkCsmsAccAddressString56Times(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
acc := csms_types.AccAddress(pk.Address())
bech32PrefixAccAddr := csms_types.GetConfig().GetBech32AccountAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixAccAddr, acc.Bytes())
require.NoError(b, err)
b.StartTimer()
for i := 0; i < 56; i++ {
str2 := acc.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkCsmsValAddressStringOneTime(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
val := csms_types.ValAddress(pk.Address())
bech32PrefixValAddr := csms_types.GetConfig().GetBech32ValidatorAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixValAddr, val.Bytes())
require.NoError(b, err)
b.StartTimer()
str2 := val.String()
require.Equal(b, str, str2)
}
}
func BenchmarkCsmsValAddressString11Times(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
val := csms_types.ValAddress(pk.Address())
bech32PrefixValAddr := csms_types.GetConfig().GetBech32ValidatorAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixValAddr, val.Bytes())
require.NoError(b, err)
b.StartTimer()
for i := 0; i < 11; i++ {
str2 := val.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkCsmsValAddressString56Times(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
val := csms_types.ValAddress(pk.Address())
bech32PrefixValAddr := csms_types.GetConfig().GetBech32ValidatorAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixValAddr, val.Bytes())
require.NoError(b, err)
b.StartTimer()
for i := 0; i < 56; i++ {
str2 := val.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkCsmsConsAddressStringOneTime(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
cons := csms_types.ConsAddress(pk.Address())
bech32PrefixConsAddr := csms_types.GetConfig().GetBech32ConsensusAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixConsAddr, cons.Bytes())
require.NoError(b, err)
b.StartTimer()
str2 := cons.String()
require.Equal(b, str, str2)
}
}
func BenchmarkCsmsConsAddressString11Times(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
cons := csms_types.ConsAddress(pk.Address())
bech32PrefixConsAddr := csms_types.GetConfig().GetBech32ConsensusAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixConsAddr, cons.Bytes())
require.NoError(b, err)
b.StartTimer()
for i := 0; i < 11; i++ {
str2 := cons.String()
require.Equal(b, str, str2)
}
}
}
func BenchmarkCsmsConsAddressString56Times(b *testing.B) {
pkBz := make([]byte, csms_ed25519.PubKeySize)
pk := &csms_ed25519.PubKey{Key: pkBz}
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk.Key)
cons := csms_types.ConsAddress(pk.Address())
bech32PrefixConsAddr := csms_types.GetConfig().GetBech32ConsensusAddrPrefix()
str, err := csms_bech32.ConvertAndEncode(bech32PrefixConsAddr, cons.Bytes())
require.NoError(b, err)
b.StartTimer()
for i := 0; i < 56; i++ {
str2 := cons.String()
require.Equal(b, str, str2)
}
}
} go.modmodule lbm-vs-cosmos
go 1.15
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
require (
github.com/cosmos/cosmos-sdk v0.45.1
github.com/line/lbm-sdk v0.46.0-rc2
github.com/stretchr/testify v1.7.1
) |
I agree with you. In my opinion, let's rollbacks these codes. @torao How about you? |
I also agree @tnasu 's opinion. |
Summary
This task is to sort out useful features in order to reduce the differences between lbm-sdk and cosmos-sdk.
Report on how effective the address format changes in #298 has worked/is expected to work, and complete the work if we're reverting it back to the cosmos-sdk implementation. Expected results are:
Parent: #549
For Admin Use
The text was updated successfully, but these errors were encountered: