From 54e7020ec53fd29c8415ed3f426ff3601bd20feb Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Wed, 22 Sep 2021 17:35:24 +0200 Subject: [PATCH] feat: stop GC while running analysis --- report/export.go | 2 ++ stdout/stdout.go | 2 ++ tui/actions.go | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/report/export.go b/report/export.go index 85ad477d6..24285795e 100644 --- a/report/export.go +++ b/report/export.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "os" + "runtime/debug" "sort" "sync" "time" @@ -83,6 +84,7 @@ func (ui *UI) AnalyzePath(path string, _ *analyze.Dir) error { wait.Add(1) go func() { defer wait.Done() + defer debug.SetGCPercent(debug.SetGCPercent(-1)) dir = ui.Analyzer.AnalyzeDir(path, ui.CreateIgnoreFunc()) }() diff --git a/stdout/stdout.go b/stdout/stdout.go index 21c6b8251..355097caf 100644 --- a/stdout/stdout.go +++ b/stdout/stdout.go @@ -5,6 +5,7 @@ import ( "io" "math" "runtime" + "runtime/debug" "sort" "sync" "time" @@ -131,6 +132,7 @@ func (ui *UI) AnalyzePath(path string, _ *analyze.Dir) error { wait.Add(1) go func() { defer wait.Done() + defer debug.SetGCPercent(debug.SetGCPercent(-1)) dir = ui.Analyzer.AnalyzeDir(path, ui.CreateIgnoreFunc()) }() diff --git a/tui/actions.go b/tui/actions.go index 0eb5a1748..ab8d86f38 100644 --- a/tui/actions.go +++ b/tui/actions.go @@ -6,6 +6,7 @@ import ( "io" "os" "runtime" + "runtime/debug" "strings" "github.com/dundee/gdu/v5/build" @@ -53,8 +54,9 @@ func (ui *UI) AnalyzePath(path string, parentDir *analyze.Dir) error { go ui.updateProgress() go func() { + defer debug.SetGCPercent(debug.SetGCPercent(-1)) currentDir := ui.Analyzer.AnalyzeDir(path, ui.CreateIgnoreFunc()) - runtime.GC() + debug.FreeOSMemory() if parentDir != nil { currentDir.Parent = parentDir