Skip to content

Commit

Permalink
⚡ avoid proto.clone in schema
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 <dominik.richter@gmail.com>
  • Loading branch information
arlimus committed Jan 26, 2024
1 parent b130500 commit 338d8c3
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 338d8c3

Please sign in to comment.