Skip to content

Commit

Permalink
resource snapshot v2 with slice (#544)
Browse files Browse the repository at this point in the history
* resource snapshot v2 with slice

* changelog

* removed v2
  • Loading branch information
EItanya authored Apr 16, 2024
1 parent c0952ff commit b8d78e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog/v0.38.2/less-snapshot-allocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changelog:
- type: NON_USER_FACING
description: Use make + len for snapshot copies to avoid allocations from growing the maps.
6 changes: 3 additions & 3 deletions pkg/resource/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s Snapshot) cloneInternal(deepCopy bool, selectors ...GVKSelectorFunc) Sna
if deepCopy {
clone[k] = copyNnsMap(v)
} else {
clone[k] = map[types.NamespacedName]client.Object{}
clone[k] = make(map[types.NamespacedName]client.Object, len(v))
maps.Copy(clone[k], v)
}
continue
Expand All @@ -78,7 +78,7 @@ func (s Snapshot) cloneInternal(deepCopy bool, selectors ...GVKSelectorFunc) Sna
if deepCopy {
clone[k] = copyNnsMap(v)
} else {
clone[k] = map[types.NamespacedName]client.Object{}
clone[k] = make(map[types.NamespacedName]client.Object, len(v))
maps.Copy(clone[k], v)
}
continue
Expand Down Expand Up @@ -127,7 +127,7 @@ func (s ClusterSnapshot) ForEachObject(
}

func copyNnsMap(m map[types.NamespacedName]client.Object) map[types.NamespacedName]client.Object {
nnsMapCopy := map[types.NamespacedName]client.Object{}
nnsMapCopy := make(map[types.NamespacedName]client.Object, len(m))
for k, v := range m {
nnsMapCopy[k] = v.DeepCopyObject().(client.Object)
}
Expand Down

0 comments on commit b8d78e6

Please sign in to comment.