Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource snapshot v2 with slice #544

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading