From 7a8316b52fb74cefccae9cb628672620aa7d8fca Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Wed, 5 Aug 2020 18:10:13 +0200 Subject: [PATCH] proc: optimize FindGoroutine by checking the cache first (#2118) --- pkg/proc/variables.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index 97b8157f..f3891bfa 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -388,6 +388,10 @@ func FindGoroutine(dbp *Target, gid int) (*G, error) { return nil, fmt.Errorf("unknown goroutine %d", gid) } + if g := dbp.gcache.partialGCache[gid]; g != nil { + return g, nil + } + // Calling GoroutinesInfo could be slow if there are many goroutines // running, check if a running goroutine has been requested first. for _, thread := range dbp.ThreadList() { @@ -397,10 +401,6 @@ func FindGoroutine(dbp *Target, gid int) (*G, error) { } } - if g := dbp.gcache.partialGCache[gid]; g != nil { - return g, nil - } - const goroutinesInfoLimit = 10 nextg := 0 for nextg >= 0 {