Subject: Re: bug#79024: 31.0.50; Multiple working trees support for VC

From: Sean Whitton <[email-masked]>
Date: Fri, 25 Jul 2025 15:30:49 +0100

Hello Spencer,

I just tried implementing an other-working-tree-p backend function for
Git and Hg.  It introduces a new and quite significant performance
problem for Git.  Consider prompting for another working tree like this:

    (completing-read prompt
                     (cl-remove-if-not #'vc-git-other-working-tree-p
                                       (project-known-project-roots))
                     nil t)

This will call vc-git-other-working-tree-p multiple times, but the
obvious implementation of vc-git-other-working-tree-p invokes 'git
worktree list' to find its answer.  So this involves invoking 'git
worktree list' over and over again, which is really slow.

This is VC-specific code which could be adapted somehow; the problem is
worse if we are considering a project-prompter API where the project
prompter receives only an opaque predicate function.  The
project-prompter has no choice but to call the predicate repeatedly.

We could set up some caching of the results in vc-git but I can't think
of a cache invalidation strategy that wouldn't break Lisp code trying to
manipulate/maintain multiple worktrees.

Do let me know if you have thoughts, but it looks like we have to go
with the other-working-trees API, renamed to known-other-working-trees.

-- 
Sean Whitton