[#376] refs: Replace []*ObjectID with []ObjectID

```
ObjectIDSlice/0_elements/to_grpc_message-8       5.64ns ± 2%    5.89ns ± 4%   +4.56%  (p=0.000 n=10+10)
ObjectIDSlice/0_elements/from_grpc_message-8     6.68ns ± 3%    6.81ns ± 8%     ~     (p=0.143 n=10+10)
ObjectIDSlice/0_elements/marshal-8               7.41ns ± 3%    7.91ns ± 4%   +6.63%  (p=0.000 n=10+10)
ObjectIDSlice/1_elements/to_grpc_message-8       69.8ns ± 3%    80.5ns ± 7%  +15.39%  (p=0.000 n=10+10)
ObjectIDSlice/1_elements/from_grpc_message-8     56.4ns ± 6%    34.7ns ± 5%  -38.55%  (p=0.000 n=10+9)
ObjectIDSlice/1_elements/marshal-8               68.4ns ± 4%    67.6ns ± 4%     ~     (p=0.404 n=10+10)
ObjectIDSlice/50_elements/to_grpc_message-8      2.52µs ± 7%    2.56µs ± 4%     ~     (p=0.315 n=10+9)
ObjectIDSlice/50_elements/from_grpc_message-8    1.83µs ± 8%    0.44µs ± 1%  -75.73%  (p=0.000 n=10+8)
ObjectIDSlice/50_elements/marshal-8              2.32µs ±17%    2.22µs ± 3%     ~     (p=0.247 n=10+10)

name                                           old alloc/op   new alloc/op   delta
ObjectIDSlice/0_elements/to_grpc_message-8        0.00B          0.00B          ~     (all equal)
ObjectIDSlice/0_elements/from_grpc_message-8      0.00B          0.00B          ~     (all equal)
ObjectIDSlice/0_elements/marshal-8                0.00B          0.00B          ~     (all equal)
ObjectIDSlice/1_elements/to_grpc_message-8        72.0B ± 0%     72.0B ± 0%     ~     (all equal)
ObjectIDSlice/1_elements/from_grpc_message-8      32.0B ± 0%     24.0B ± 0%  -25.00%  (p=0.000 n=10+10)
ObjectIDSlice/1_elements/marshal-8                48.0B ± 0%     48.0B ± 0%     ~     (all equal)
ObjectIDSlice/50_elements/to_grpc_message-8      3.62kB ± 0%    3.62kB ± 0%     ~     (all equal)
ObjectIDSlice/50_elements/from_grpc_message-8    1.62kB ± 0%    1.28kB ± 0%  -20.79%  (p=0.000 n=10+10)
ObjectIDSlice/50_elements/marshal-8              2.05kB ± 0%    2.05kB ± 0%     ~     (all equal)

name                                           old allocs/op  new allocs/op  delta
ObjectIDSlice/0_elements/to_grpc_message-8         0.00           0.00          ~     (all equal)
ObjectIDSlice/0_elements/from_grpc_message-8       0.00           0.00          ~     (all equal)
ObjectIDSlice/0_elements/marshal-8                 0.00           0.00          ~     (all equal)
ObjectIDSlice/1_elements/to_grpc_message-8         2.00 ± 0%      2.00 ± 0%     ~     (all equal)
ObjectIDSlice/1_elements/from_grpc_message-8       2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)
ObjectIDSlice/1_elements/marshal-8                 1.00 ± 0%      1.00 ± 0%     ~     (all equal)
ObjectIDSlice/50_elements/to_grpc_message-8        51.0 ± 0%      51.0 ± 0%     ~     (all equal)
ObjectIDSlice/50_elements/from_grpc_message-8      51.0 ± 0%       1.0 ± 0%  -98.04%  (p=0.000 n=10+10)
ObjectIDSlice/50_elements/marshal-8                1.00 ± 0%      1.00 ± 0%     ~     (all equal)
```

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-01 15:50:09 +03:00 committed by Alex Vanin
parent 529d636ede
commit 84daaf59ef
9 changed files with 32 additions and 40 deletions

View file

@ -19,7 +19,7 @@ type DataAuditResult struct {
pubKey []byte pubKey []byte
passSG, failSG []*refs.ObjectID passSG, failSG []refs.ObjectID
failNodes, passNodes [][]byte failNodes, passNodes [][]byte
@ -91,7 +91,7 @@ func (a *DataAuditResult) SetPublicKey(v []byte) {
} }
// GetPassSG returns list of Storage Groups that passed audit PoR stage. // GetPassSG returns list of Storage Groups that passed audit PoR stage.
func (a *DataAuditResult) GetPassSG() []*refs.ObjectID { func (a *DataAuditResult) GetPassSG() []refs.ObjectID {
if a != nil { if a != nil {
return a.passSG return a.passSG
} }
@ -100,14 +100,14 @@ func (a *DataAuditResult) GetPassSG() []*refs.ObjectID {
} }
// SetPassSG sets list of Storage Groups that passed audit PoR stage. // SetPassSG sets list of Storage Groups that passed audit PoR stage.
func (a *DataAuditResult) SetPassSG(v []*refs.ObjectID) { func (a *DataAuditResult) SetPassSG(v []refs.ObjectID) {
if a != nil { if a != nil {
a.passSG = v a.passSG = v
} }
} }
// GetFailSG returns list of Storage Groups that failed audit PoR stage. // GetFailSG returns list of Storage Groups that failed audit PoR stage.
func (a *DataAuditResult) GetFailSG() []*refs.ObjectID { func (a *DataAuditResult) GetFailSG() []refs.ObjectID {
if a != nil { if a != nil {
return a.failSG return a.failSG
} }
@ -116,7 +116,7 @@ func (a *DataAuditResult) GetFailSG() []*refs.ObjectID {
} }
// SetFailSG sets list of Storage Groups that failed audit PoR stage. // SetFailSG sets list of Storage Groups that failed audit PoR stage.
func (a *DataAuditResult) SetFailSG(v []*refs.ObjectID) { func (a *DataAuditResult) SetFailSG(v []refs.ObjectID) {
if a != nil { if a != nil {
a.failSG = v a.failSG = v
} }

View file

@ -34,7 +34,7 @@ type SplitHeader struct {
parHdr *Header parHdr *Header
children []*refs.ObjectID children []refs.ObjectID
splitID []byte splitID []byte
} }
@ -228,7 +228,7 @@ type SearchRequest struct {
} }
type SearchResponseBody struct { type SearchResponseBody struct {
idList []*refs.ObjectID idList []refs.ObjectID
} }
type SearchResponse struct { type SearchResponse struct {
@ -500,7 +500,7 @@ func (h *SplitHeader) SetParentHeader(v *Header) {
} }
} }
func (h *SplitHeader) GetChildren() []*refs.ObjectID { func (h *SplitHeader) GetChildren() []refs.ObjectID {
if h != nil { if h != nil {
return h.children return h.children
} }
@ -508,7 +508,7 @@ func (h *SplitHeader) GetChildren() []*refs.ObjectID {
return nil return nil
} }
func (h *SplitHeader) SetChildren(v []*refs.ObjectID) { func (h *SplitHeader) SetChildren(v []refs.ObjectID) {
if h != nil { if h != nil {
h.children = v h.children = v
} }
@ -1316,7 +1316,7 @@ func (r *SearchRequest) SetBody(v *SearchRequestBody) {
} }
} }
func (r *SearchResponseBody) GetIDList() []*refs.ObjectID { func (r *SearchResponseBody) GetIDList() []refs.ObjectID {
if r != nil { if r != nil {
return r.idList return r.idList
} }
@ -1324,7 +1324,7 @@ func (r *SearchResponseBody) GetIDList() []*refs.ObjectID {
return nil return nil
} }
func (r *SearchResponseBody) SetIDList(v []*refs.ObjectID) { func (r *SearchResponseBody) SetIDList(v []refs.ObjectID) {
if r != nil { if r != nil {
r.idList = v r.idList = v
} }

View file

@ -15,9 +15,8 @@ func BenchmarkObjectIDSlice(b *testing.B) {
} }
func benchmarkObjectIDSlice(b *testing.B, size int) { func benchmarkObjectIDSlice(b *testing.B, size int) {
ids := make([]*ObjectID, size) ids := make([]ObjectID, size)
for i := range ids { for i := range ids {
ids[i] = new(ObjectID)
ids[i].val = make([]byte, 32) ids[i].val = make([]byte, 32)
rand.Read(ids[i].val) rand.Read(ids[i].val)
} }

View file

@ -110,7 +110,7 @@ func (o *ObjectID) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func ObjectIDListToGRPCMessage(ids []*ObjectID) (res []*refs.ObjectID) { func ObjectIDListToGRPCMessage(ids []ObjectID) (res []*refs.ObjectID) {
if ids != nil { if ids != nil {
res = make([]*refs.ObjectID, 0, len(ids)) res = make([]*refs.ObjectID, 0, len(ids))
@ -122,23 +122,17 @@ func ObjectIDListToGRPCMessage(ids []*ObjectID) (res []*refs.ObjectID) {
return return
} }
func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []*ObjectID, err error) { func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []ObjectID, err error) {
if idsV2 != nil { if idsV2 != nil {
res = make([]*ObjectID, 0, len(idsV2)) res = make([]ObjectID, len(idsV2))
for i := range idsV2 { for i := range idsV2 {
var id *ObjectID
if idsV2[i] != nil { if idsV2[i] != nil {
id = new(ObjectID) err = res[i].FromGRPCMessage(idsV2[i])
err = id.FromGRPCMessage(idsV2[i])
if err != nil { if err != nil {
return return
} }
} }
res = append(res, id)
} }
} }

View file

@ -104,9 +104,9 @@ func (o *ObjectID) StableMarshal(buf []byte) ([]byte, error) {
// ObjectIDNestedListSize returns byte length of nested // ObjectIDNestedListSize returns byte length of nested
// repeated ObjectID field with fNum number. // repeated ObjectID field with fNum number.
func ObjectIDNestedListSize(fNum int64, ids []*ObjectID) (sz int) { func ObjectIDNestedListSize(fNum int64, ids []ObjectID) (sz int) {
for i := range ids { for i := range ids {
sz += proto.NestedStructureSize(fNum, ids[i]) sz += proto.NestedStructureSize(fNum, &ids[i])
} }
return return
@ -122,11 +122,11 @@ func (o *ObjectID) StableSize() int {
// ObjectIDNestedListMarshal writes protobuf repeated ObjectID field // ObjectIDNestedListMarshal writes protobuf repeated ObjectID field
// with fNum number to buf. // with fNum number to buf.
func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []*ObjectID) (off int, err error) { func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int, err error) {
for i := range ids { for i := range ids {
var n int var n int
n, err = proto.NestedStructureMarshal(fNum, buf[off:], ids[i]) n, err = proto.NestedStructureMarshal(fNum, buf[off:], &ids[i])
if err != nil { if err != nil {
return return
} }

View file

@ -48,13 +48,13 @@ func GenerateObjectID(empty bool) *refs.ObjectID {
return m return m
} }
func GenerateObjectIDs(empty bool) []*refs.ObjectID { func GenerateObjectIDs(empty bool) []refs.ObjectID {
var ids []*refs.ObjectID var ids []refs.ObjectID
if !empty { if !empty {
ids = append(ids, ids = append(ids,
GenerateObjectID(false), *GenerateObjectID(false),
GenerateObjectID(false), *GenerateObjectID(false),
) )
} }

View file

@ -13,7 +13,7 @@ type StorageGroup struct {
exp uint64 exp uint64
members []*refs.ObjectID members []refs.ObjectID
} }
// GetValidationDataSize of unified storage group structure. // GetValidationDataSize of unified storage group structure.
@ -66,7 +66,7 @@ func (s *StorageGroup) SetExpirationEpoch(v uint64) {
// GetMembers of unified storage group structure. Members are objects of // GetMembers of unified storage group structure. Members are objects of
// storage group. // storage group.
func (s *StorageGroup) GetMembers() []*refs.ObjectID { func (s *StorageGroup) GetMembers() []refs.ObjectID {
if s != nil { if s != nil {
return s.members return s.members
} }
@ -76,7 +76,7 @@ func (s *StorageGroup) GetMembers() []*refs.ObjectID {
// SetMembers into unified storage group structure. Members are objects of // SetMembers into unified storage group structure. Members are objects of
// storage group. // storage group.
func (s *StorageGroup) SetMembers(v []*refs.ObjectID) { func (s *StorageGroup) SetMembers(v []refs.ObjectID) {
if s != nil { if s != nil {
s.members = v s.members = v
} }

View file

@ -43,7 +43,7 @@ func (s *Tombstone) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
for i := range s.members { for i := range s.members {
n, err = proto.NestedStructureMarshal(membersFNum, buf[offset:], s.members[i]) n, err = proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i])
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -62,9 +62,8 @@ func (s *Tombstone) StableSize() (size int) {
size += proto.UInt64Size(expFNum, s.exp) size += proto.UInt64Size(expFNum, s.exp)
size += proto.BytesSize(splitIDFNum, s.splitID) size += proto.BytesSize(splitIDFNum, s.splitID)
for i := range s.members { for i := range s.members {
size += proto.NestedStructureSize(membersFNum, s.members[i]) size += proto.NestedStructureSize(membersFNum, &s.members[i])
} }
return size return size

View file

@ -11,7 +11,7 @@ type Tombstone struct {
splitID []byte splitID []byte
members []*refs.ObjectID members []refs.ObjectID
} }
// GetExpirationEpoch returns number of tombstone expiration epoch. // GetExpirationEpoch returns number of tombstone expiration epoch.
@ -47,7 +47,7 @@ func (s *Tombstone) SetSplitID(v []byte) {
} }
// GetMembers returns list of objects to be deleted. // GetMembers returns list of objects to be deleted.
func (s *Tombstone) GetMembers() []*refs.ObjectID { func (s *Tombstone) GetMembers() []refs.ObjectID {
if s != nil { if s != nil {
return s.members return s.members
} }
@ -56,7 +56,7 @@ func (s *Tombstone) GetMembers() []*refs.ObjectID {
} }
// SetMembers sets list of objects to be deleted. // SetMembers sets list of objects to be deleted.
func (s *Tombstone) SetMembers(v []*refs.ObjectID) { func (s *Tombstone) SetMembers(v []refs.ObjectID) {
if s != nil { if s != nil {
s.members = v s.members = v
} }