Skip to content

Commit 2cb0707

Browse files
committed
Reduce peak memory during edge grouping
Delete edges from the input map while iterating to free memory as the grouped map is built. This halves peak memory usage during groupEdgesByIdentityDigest (~1.4GB to ~700MB with ~1M edges). Safe because Go allows map deletion during range, and all callers do not use the edges map after grouping. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
1 parent d4afa36 commit 2cb0707

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

internal/promoter/image/sign.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ func groupEdgesByIdentityDigest(edges map[promotion.Edge]any) [][]promotion.Edge
548548
grouped := make(map[key][]promotion.Edge, len(edges)/2)
549549

550550
for edge := range edges {
551+
delete(edges, edge) // free as we go to reduce peak memory
552+
551553
// Skip metadata layers
552554
if strings.HasSuffix(string(edge.DstImageTag.Tag), ".sig") ||
553555
strings.HasSuffix(string(edge.DstImageTag.Tag), ".att") ||

0 commit comments

Comments
 (0)