From 84daaf59eff0c0eafb2fe5780989a7712fe857fb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 1 Mar 2022 15:50:09 +0300 Subject: [PATCH] [#376] refs: Replace []*ObjectID with []ObjectID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` 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 --- audit/types.go | 10 +++++----- object/types.go | 12 ++++++------ refs/bench_test.go | 3 +-- refs/convert.go | 14 ++++---------- refs/marshal.go | 8 ++++---- refs/test/generate.go | 8 ++++---- storagegroup/types.go | 6 +++--- tombstone/marshal.go | 5 ++--- tombstone/types.go | 6 +++--- 9 files changed, 32 insertions(+), 40 deletions(-) diff --git a/audit/types.go b/audit/types.go index 35aa52a..8245b2a 100644 --- a/audit/types.go +++ b/audit/types.go @@ -19,7 +19,7 @@ type DataAuditResult struct { pubKey []byte - passSG, failSG []*refs.ObjectID + passSG, failSG []refs.ObjectID failNodes, passNodes [][]byte @@ -91,7 +91,7 @@ func (a *DataAuditResult) SetPublicKey(v []byte) { } // 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 { return a.passSG } @@ -100,14 +100,14 @@ func (a *DataAuditResult) GetPassSG() []*refs.ObjectID { } // 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 { a.passSG = v } } // 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 { return a.failSG } @@ -116,7 +116,7 @@ func (a *DataAuditResult) GetFailSG() []*refs.ObjectID { } // 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 { a.failSG = v } diff --git a/object/types.go b/object/types.go index 596ed3e..63002bc 100644 --- a/object/types.go +++ b/object/types.go @@ -34,7 +34,7 @@ type SplitHeader struct { parHdr *Header - children []*refs.ObjectID + children []refs.ObjectID splitID []byte } @@ -228,7 +228,7 @@ type SearchRequest struct { } type SearchResponseBody struct { - idList []*refs.ObjectID + idList []refs.ObjectID } 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 { return h.children } @@ -508,7 +508,7 @@ func (h *SplitHeader) GetChildren() []*refs.ObjectID { return nil } -func (h *SplitHeader) SetChildren(v []*refs.ObjectID) { +func (h *SplitHeader) SetChildren(v []refs.ObjectID) { if h != nil { 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 { return r.idList } @@ -1324,7 +1324,7 @@ func (r *SearchResponseBody) GetIDList() []*refs.ObjectID { return nil } -func (r *SearchResponseBody) SetIDList(v []*refs.ObjectID) { +func (r *SearchResponseBody) SetIDList(v []refs.ObjectID) { if r != nil { r.idList = v } diff --git a/refs/bench_test.go b/refs/bench_test.go index dc5b393..aed5f79 100644 --- a/refs/bench_test.go +++ b/refs/bench_test.go @@ -15,9 +15,8 @@ func BenchmarkObjectIDSlice(b *testing.B) { } func benchmarkObjectIDSlice(b *testing.B, size int) { - ids := make([]*ObjectID, size) + ids := make([]ObjectID, size) for i := range ids { - ids[i] = new(ObjectID) ids[i].val = make([]byte, 32) rand.Read(ids[i].val) } diff --git a/refs/convert.go b/refs/convert.go index bb6e988..feb851f 100644 --- a/refs/convert.go +++ b/refs/convert.go @@ -110,7 +110,7 @@ func (o *ObjectID) FromGRPCMessage(m grpc.Message) error { return nil } -func ObjectIDListToGRPCMessage(ids []*ObjectID) (res []*refs.ObjectID) { +func ObjectIDListToGRPCMessage(ids []ObjectID) (res []*refs.ObjectID) { if ids != nil { res = make([]*refs.ObjectID, 0, len(ids)) @@ -122,23 +122,17 @@ func ObjectIDListToGRPCMessage(ids []*ObjectID) (res []*refs.ObjectID) { return } -func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []*ObjectID, err error) { +func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []ObjectID, err error) { if idsV2 != nil { - res = make([]*ObjectID, 0, len(idsV2)) + res = make([]ObjectID, len(idsV2)) for i := range idsV2 { - var id *ObjectID - if idsV2[i] != nil { - id = new(ObjectID) - - err = id.FromGRPCMessage(idsV2[i]) + err = res[i].FromGRPCMessage(idsV2[i]) if err != nil { return } } - - res = append(res, id) } } diff --git a/refs/marshal.go b/refs/marshal.go index c496221..aa04b63 100644 --- a/refs/marshal.go +++ b/refs/marshal.go @@ -104,9 +104,9 @@ func (o *ObjectID) StableMarshal(buf []byte) ([]byte, error) { // ObjectIDNestedListSize returns byte length of nested // 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 { - sz += proto.NestedStructureSize(fNum, ids[i]) + sz += proto.NestedStructureSize(fNum, &ids[i]) } return @@ -122,11 +122,11 @@ func (o *ObjectID) StableSize() int { // ObjectIDNestedListMarshal writes protobuf repeated ObjectID field // 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 { var n int - n, err = proto.NestedStructureMarshal(fNum, buf[off:], ids[i]) + n, err = proto.NestedStructureMarshal(fNum, buf[off:], &ids[i]) if err != nil { return } diff --git a/refs/test/generate.go b/refs/test/generate.go index 3912ffa..7a142e3 100644 --- a/refs/test/generate.go +++ b/refs/test/generate.go @@ -48,13 +48,13 @@ func GenerateObjectID(empty bool) *refs.ObjectID { return m } -func GenerateObjectIDs(empty bool) []*refs.ObjectID { - var ids []*refs.ObjectID +func GenerateObjectIDs(empty bool) []refs.ObjectID { + var ids []refs.ObjectID if !empty { ids = append(ids, - GenerateObjectID(false), - GenerateObjectID(false), + *GenerateObjectID(false), + *GenerateObjectID(false), ) } diff --git a/storagegroup/types.go b/storagegroup/types.go index 6c493ed..38f66f6 100644 --- a/storagegroup/types.go +++ b/storagegroup/types.go @@ -13,7 +13,7 @@ type StorageGroup struct { exp uint64 - members []*refs.ObjectID + members []refs.ObjectID } // 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 // storage group. -func (s *StorageGroup) GetMembers() []*refs.ObjectID { +func (s *StorageGroup) GetMembers() []refs.ObjectID { if s != nil { return s.members } @@ -76,7 +76,7 @@ func (s *StorageGroup) GetMembers() []*refs.ObjectID { // SetMembers into unified storage group structure. Members are objects of // storage group. -func (s *StorageGroup) SetMembers(v []*refs.ObjectID) { +func (s *StorageGroup) SetMembers(v []refs.ObjectID) { if s != nil { s.members = v } diff --git a/tombstone/marshal.go b/tombstone/marshal.go index f39d5d9..cd778b9 100644 --- a/tombstone/marshal.go +++ b/tombstone/marshal.go @@ -43,7 +43,7 @@ func (s *Tombstone) StableMarshal(buf []byte) ([]byte, error) { offset += n 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 { return nil, err } @@ -62,9 +62,8 @@ func (s *Tombstone) StableSize() (size int) { size += proto.UInt64Size(expFNum, s.exp) size += proto.BytesSize(splitIDFNum, s.splitID) - for i := range s.members { - size += proto.NestedStructureSize(membersFNum, s.members[i]) + size += proto.NestedStructureSize(membersFNum, &s.members[i]) } return size diff --git a/tombstone/types.go b/tombstone/types.go index 2bcc19d..6cce852 100644 --- a/tombstone/types.go +++ b/tombstone/types.go @@ -11,7 +11,7 @@ type Tombstone struct { splitID []byte - members []*refs.ObjectID + members []refs.ObjectID } // 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. -func (s *Tombstone) GetMembers() []*refs.ObjectID { +func (s *Tombstone) GetMembers() []refs.ObjectID { if s != nil { return s.members } @@ -56,7 +56,7 @@ func (s *Tombstone) GetMembers() []*refs.ObjectID { } // 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 { s.members = v }