From c185b7d00464a72db0edcf27709739e742104b65 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Thu, 17 Sep 2015 13:33:42 -0400 Subject: [PATCH] proc/proc: Cache 'GoroutineInfo' result during halt The GoroutineInfo method can be slow if there are many goroutines. This patch caches the results during a halt so they are not needlessly recomputed. Fixes #234 --- proc/proc.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/proc/proc.go b/proc/proc.go index fa5146ff..9471726e 100644 --- a/proc/proc.go +++ b/proc/proc.go @@ -39,6 +39,7 @@ type Process struct { // Normally SelectedGoroutine is CurrentThread.GetG, it will not be only if SwitchGoroutine is called with a goroutine that isn't attached to a thread SelectedGoroutine *G + allGCache []*G dwarf *dwarf.Data goSymTable *gosym.Table frameEntries frame.FrameDescriptionEntries @@ -446,6 +447,10 @@ func (dbp *Process) SwitchGoroutine(gid int) error { // Returns an array of G structures representing the information // Delve cares about from the internal runtime G structure. func (dbp *Process) GoroutinesInfo() ([]*G, error) { + if dbp.allGCache != nil { + return dbp.allGCache, nil + } + var ( threadg = map[int]*Thread{} allg []*G @@ -498,6 +503,7 @@ func (dbp *Process) GoroutinesInfo() ([]*G, error) { } allg = append(allg, g) } + dbp.allGCache = allg return allg, nil } @@ -668,6 +674,7 @@ func (dbp *Process) handleBreakpointOnThread(id int) (*Thread, error) { } func (dbp *Process) run(fn func() error) error { + dbp.allGCache = nil if dbp.exited { return fmt.Errorf("process has already exited") }