status-im / status-console-client

Status messaging console user interface
Mozilla Public License 2.0
10 stars 2 forks source link

Marshal key without a curve #38

Closed dshulyak closed 5 years ago

dshulyak commented 5 years ago

Key with a curve takes in total 320 bytes. Without curve we can fit it into 34 bytes. But more importantly marshalling all curve parameters is slower than adding single byte identifier. So loading 10000 messages was improved From:

BenchmarkLoadMessages-8            2     860127256 ns/op

To:

BenchmarkLoadMessages-8            3     343789516 ns/op
adambabik commented 5 years ago

Awesome finding! One suggestion is to implement encoding.BinaryMarshaler by Contact struct instead. That would make sure that Contact is serialized always in the same way.

dshulyak commented 5 years ago

key is marshaled as a separate field now. i can check if it makes sense to define our type for *ecdsa.PublicKey

adambabik commented 5 years ago

Ah right, gob is not used anymore. So maybe something like contact.PublicKeyBytes(). Of course the implementation can be as a function and PublicKeyBytes can just use it. But if currently, we marshal public key only in one place, it does not matter.