"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
Re: tog doesn't want you to quit right away
To:
Christian Weisgerber <naddy@mips.inka.de>
Cc:
gameoftrees@openbsd.org
Date:
Wed, 08 Jan 2025 18:14:12 +1100

Download raw body.

Thread
Christian Weisgerber <naddy@mips.inka.de> wrote:
> Go into a preferably large work tree (like OpenBSD src), start tog,
> and try to quit immediately.  tog will take some time before it
> exits.  The effect is more pronounced the larger the work tree and
> the slower the machine.
> 
> Interestingly you can interact with tog right away and it is
> responsive, but quitting it just takes time.
> 
> I think this has been happening since the worktree diff feature was
> added.  It also doesn't happen when you start tog inside a repository,
> which jibes.


Thanks, naddy!

Does the below diff improve this lag-time for you? I've only been able
to test on a relatively fast machine where the improvement is still
quite noticeable in src.git, but I don't have immediate access to a
slower machine for further testing.


commit 0991f61b344c8d3a5c5df3b3d93723b03f923dad (main)
from: Mark Jamsek <mark@jamsek.dev>
date: Wed Jan  8 06:58:38 2025 UTC

tog: pass user quit state to worktree state cancel callback

Reported by naddy: the main thread has to wait for the log thread to
fetch work tree state before acting on the user's quit input, which
produces a noticeable lag between entering 'q' and tog actually
terminating. Pass the quit flag to the cancel callback so we can act
on it sooner.

M  tog/tog.c  |  16+  8-

1 file changed, 16 insertions(+), 8 deletions(-)

commit - 7f59939ae67ad8168afa53ad5c1fa4f830269290
commit + 0991f61b344c8d3a5c5df3b3d93723b03f923dad
blob - da3af395b2dbac57ee04e516108f32c3ee9ba1cd
blob + 0ccc6a0f788f55d0c7f1bd60778f977402cfd4d8
--- tog/tog.c
+++ tog/tog.c
@@ -3140,7 +3140,15 @@ push_worktree_entry(struct tog_log_thread_args *ta, in
 static const struct got_error *
 check_cancelled(void *arg)
 {
-	if (tog_sigint_received || tog_sigpipe_received)
+	int rc, quit = 0;
+
+	if ((rc = pthread_mutex_lock(&tog_mutex)) != 0)
+		return got_error_set_errno(rc, "pthread_mutex_lock");
+	if (tog_sigint_received || tog_sigpipe_received || *((int *)arg))
+		quit = 1;
+	if ((rc = pthread_mutex_unlock(&tog_mutex)) != 0)
+		return got_error_set_errno(rc, "pthread_mutex_unlock");
+	if (quit)
 		return got_error(GOT_ERR_CANCELLED);
 	return NULL;
 }
@@ -3212,12 +3220,9 @@ tog_worktree_status(struct tog_log_thread_args *ta)
 		goto done;
 
 	err = got_worktree_status(wt, &paths, ta->repo, 0,
-	    check_local_changes, &wt_state, check_cancelled, NULL);
-	if (err != NULL) {
-		if (err->code != GOT_ERR_CANCELLED)
-			goto done;
-		err = NULL;
-	}
+	    check_local_changes, &wt_state, check_cancelled, ta->quit);
+	if (err != NULL)
+		goto done;
 
 	if (wt_state != 0) {
 		err = get_author(&wctx->wt_author, ta->repo, wt);
@@ -4049,8 +4054,11 @@ log_thread(void *arg)
 				goto done;
 			}
 			err = tog_worktree_status(a);
-			if (err != NULL)
+			if (err != NULL) {
+				if (err->code == GOT_ERR_CANCELLED)
+					err = NULL;
 				goto done;
+			}
 			errcode = pthread_mutex_lock(&tog_mutex);
 			if (errcode) {
 				err = got_error_set_errno(errcode,


-- 
Mark Jamsek <https://bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68