state: use open-coded array (de)serialization for accounts
We're spending a lot of time here, 100K blocks import starting at 1.4M, before this patch: real 4m17,748s user 6m23,316s sys 0m37,866s After: real 3m54,968s user 5m56,547s sys 0m39,398s 9% is quite a substantial improvement to justify this change.
This commit is contained in:
parent
0d0a27d271
commit
6896b40dee
1 changed files with 9 additions and 3 deletions
|
@ -49,8 +49,11 @@ func (s *Account) DecodeBinary(br *io.BinReader) {
|
|||
for i := 0; i < int(lenBalances); i++ {
|
||||
key := util.Uint256{}
|
||||
br.ReadBytes(key[:])
|
||||
ubs := make([]UnspentBalance, 0)
|
||||
br.ReadArray(&ubs)
|
||||
len := int(br.ReadVarUint())
|
||||
ubs := make([]UnspentBalance, len)
|
||||
for j := 0; j < len; j++ {
|
||||
ubs[j].DecodeBinary(br)
|
||||
}
|
||||
s.Balances[key] = ubs
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +68,10 @@ func (s *Account) EncodeBinary(bw *io.BinWriter) {
|
|||
bw.WriteVarUint(uint64(len(s.Balances)))
|
||||
for k, v := range s.Balances {
|
||||
bw.WriteBytes(k[:])
|
||||
bw.WriteArray(v)
|
||||
bw.WriteVarUint(uint64(len(v)))
|
||||
for i := range v {
|
||||
v[i].EncodeBinary(bw)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue