From 7aca12fc8b59178eaea28d3bece94620cd4f83ce Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 25 Jan 2024 22:46:51 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20avoid=20proto.clone=20in=20schema?= =?UTF-8?q?=20(#3125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have some indication that it uses up way more memory than it should. Also using clone at this place is... a bit lazy, considering it uses reflections. Signed-off-by: Dominik Richter --- providers-sdk/v1/resources/schema.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/providers-sdk/v1/resources/schema.go b/providers-sdk/v1/resources/schema.go index 5339829147..b1f2a3e5db 100644 --- a/providers-sdk/v1/resources/schema.go +++ b/providers-sdk/v1/resources/schema.go @@ -3,8 +3,6 @@ package resources -import "google.golang.org/protobuf/proto" - // Add another schema and return yourself. other may be nil. // The other schema overrides specifications in this schema, unless // it is trying to extend a resource whose base is already defined. @@ -55,7 +53,24 @@ func (s *Schema) Add(other *Schema) *Schema { existing.Fields[fk] = fv } } else { - s.Resources[k] = proto.Clone(v).(*ResourceInfo) + ri := &ResourceInfo{ + Id: v.Id, + Name: v.Name, + Fields: make(map[string]*Field, len(v.Fields)), + Init: v.Init, + ListType: v.ListType, + Title: v.Title, + Desc: v.Desc, + Private: v.Private, + IsExtension: v.IsExtension, + MinMondooVersion: v.MinMondooVersion, + Defaults: v.Defaults, + Provider: v.Provider, + } + for k, v := range v.Fields { + ri.Fields[k] = v + } + s.Resources[k] = ri } }