From 898f5651163d8ff9a28889003450872a1b27f29f Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 9 Aug 2025 11:45:52 +0200 Subject: [PATCH] Fix delay with flicking through files or commits when git diff is very slow One reason why git diff can be very slow is when "diff.algorithm = histogram" is being used. In this case, showing a very long single-file diff can take seconds to load, and you'll see the "loading..." message in the main view until we got the first lines of the diff to show. There's nothing really we can do about this delay; however, when switching to another, shorter file (or commit) while the "loading..." message is still showing, this switch should be instantaneous. And it was before 0.54.0, but we broke this in 0.54.0 with 8d7740a5acab (#4782); now users have to wait for the slow git diff command to output more text before the switch occurs. To fix this, don't block waiting for the process to terminate if we just stopped it. --- pkg/tasks/tasks.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/tasks/tasks.go b/pkg/tasks/tasks.go index 5401b1714..27fcf817b 100644 --- a/pkg/tasks/tasks.go +++ b/pkg/tasks/tasks.go @@ -291,11 +291,15 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p refreshViewIfStale() - if err := cmd.Wait(); err != nil { - select { - case <-opts.Stop: - // it's fine if we've killed this program ourselves - default: + select { + case <-opts.Stop: + // If we stopped the task, don't block waiting for it; this could cause a delay if + // the process takes a while until it actually terminates. We still want to call + // Wait to reclaim any resources, but do it on a background goroutine, and ignore + // any errors. + go func() { _ = cmd.Wait() }() + default: + if err := cmd.Wait(); err != nil { self.Log.Errorf("Unexpected error when running cmd task: %v; Failed command: %v %v", err, cmd.Path, cmd.Args) } }