Skip to content

Commit

Permalink
⚡ avoid proto.clone in schema (#3125)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
arlimus authored Jan 26, 2024
1 parent b130500 commit 7aca12f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions providers-sdk/v1/resources/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 7aca12f

Please sign in to comment.