Skip to content

Commit

Permalink
perf: Improve SortOrderTransformer and use AppendMany
Browse files Browse the repository at this point in the history
Reduce calls to CurId when sorting, and use AppendMany when collecting
results.
  • Loading branch information
chlunde committed Apr 16, 2024
1 parent 0fe5421 commit f6ed5d5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions plugin/builtin/sortordertransformer/SortOrderTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ func (p *plugin) Transform(m resmap.ResMap) (err error) {

// Clear the map and re-add the resources in the sorted order.
m.Clear()
for _, r := range s.resources {
err := m.Append(r)
if err != nil {
return errors.WrapPrefixf(err, "SortOrderTransformer: Failed to append to resources")
}
err := m.AppendMany(s.resources...)
if err != nil {
return errors.WrapPrefixf(err, "SortOrderTransformer: Failed to append to resources")
}
}
return nil
Expand All @@ -102,6 +100,7 @@ func (p *plugin) Transform(m resmap.ResMap) (err error) {
type legacyIDSorter struct {
// resids only stores the metadata of the object. This is an optimization as
// it's expensive to compute these again and again during ordering.

resids []resid.ResId
// Initially, we sorted the metadata (ResId) of each object and then called GetByCurrentId on each to construct the final list.
// The problem is that GetByCurrentId is inefficient and does a linear scan in a list every time we do that.
Expand Down

0 comments on commit f6ed5d5

Please sign in to comment.