From d83184ced12a13d0bf2568d44294040b650424eb Mon Sep 17 00:00:00 2001 From: Jin Dong Date: Mon, 26 Aug 2024 18:29:57 -0700 Subject: [PATCH] avoid repeated calls in Tricolor gc Signed-off-by: Jin Dong --- pkg/gc/gc.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/gc/gc.go b/pkg/gc/gc.go index 079a6eae9..67d9a0476 100644 --- a/pkg/gc/gc.go +++ b/pkg/gc/gc.go @@ -69,12 +69,14 @@ func Tricolor(roots []Node, refs func(ref Node) ([]Node, error)) (map[Node]struc ) grays = append(grays, roots...) + for _, root := range roots { + seen[root] = struct{}{} // pre-mark this as not-white + } for len(grays) > 0 { // Pick any gray object id := grays[len(grays)-1] // effectively "depth first" because first element grays = grays[:len(grays)-1] - seen[id] = struct{}{} // post-mark this as not-white rs, err := refs(id) if err != nil { return nil, err @@ -84,6 +86,7 @@ func Tricolor(roots []Node, refs func(ref Node) ([]Node, error)) (map[Node]struc for _, target := range rs { if _, ok := seen[target]; !ok { grays = append(grays, target) + seen[target] = struct{}{} } }