🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
3 messages
3 total messages Started by "Maik Riechert via GitGitGadget" Sat, 28 Nov 2026 23:06
[PATCH] worktree add: skip HEAD reads for destination checks
#4055
Author: "Maik Riechert via GitGitGadget"
Date: Sat, 28 Nov 2026 23:06
46 lines
12119 bytes
From: Maik Riechert <letmaik@outlook.com>

add_worktree() calls get_worktrees() to check whether the destination
matches a registered worktree. This also resolves HEAD for the
enumerated worktrees, although check_candidate_path() only needs their
paths, IDs and lock state.

Use get_worktrees_without_reading_head() for the destination check to
avoid these unnecessary lookups.

Detached git worktree add --no-checkout with 200 existing linked
worktrees. Median of seven runs per version, with warm caches:

              before     after
files         11.13 ms    6.77 ms
reftable      18.86 ms    7.60 ms

Signed-off-by: Maik Riechert <letmaik@outlook.com>
---
    worktree add: skip HEAD reads for destination checks

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2339%2Fletmaik%2Fworktree-add-path-checks-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2339/letmaik/worktree-add-path-checks-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2339

 builtin/worktree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index 77ecd0f71f..82a93b0adf 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -473,7 +473,7 @@ static int add_worktree(const char *path, const char *refname,
 	struct ref_store *wt_refs;
 	struct repo_config_values *cfg = repo_config_values(the_repository);
 
-	worktrees = get_worktrees(the_repository);
+	worktrees = get_worktrees_without_reading_head(the_repository);
 	check_candidate_path(path, opts->force, worktrees, "add");
 	free_worktrees(worktrees);
 	worktrees = NULL;

base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
-- 
gitgitgadget
Re: [PATCH] worktree add: skip HEAD reads for destination checks
#4061
Author: Junio C Hamano
Date: Sun, 29 Nov 2026 05:01
28 lines
13455 bytes
"Maik Riechert via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Maik Riechert <letmaik@outlook.com>
>
> add_worktree() calls get_worktrees() to check whether the destination
> matches a registered worktree. This also resolves HEAD for the
> enumerated worktrees, although check_candidate_path() only needs their
> paths, IDs and lock state.
>
> Use get_worktrees_without_reading_head() for the destination check to
> avoid these unnecessary lookups.
>
> Detached git worktree add --no-checkout with 200 existing linked
> worktrees. Median of seven runs per version, with warm caches:

This is a very minor nit, but the above reads like a note fragment
without a verb.  Something like "Measured with 'git worktree add
--detach --no-checkout' on a repository with 200 existing linked
worktrees (median of seven runs per version, warm caches)" might read a
bit more smoothly.

>               before     after
> files         11.13 ms    6.77 ms
> reftable      18.86 ms    7.60 ms

Nice to see that avoiding extra work yields a simple, straightforward,
and expected payoff ;-)
[PATCH v2] worktree add: skip HEAD reads for destination checks
#4062
Author: "Maik Riechert via GitGitGadget"
Date: Sun, 29 Nov 2026 05:41
69 lines
13303 bytes
From: Maik Riechert <letmaik@outlook.com>

add_worktree() calls get_worktrees() to check whether the destination
matches a registered worktree. This also resolves HEAD for the
enumerated worktrees, although check_candidate_path() only needs their
paths, IDs and lock state.

Use get_worktrees_without_reading_head() for the destination check to
avoid these unnecessary lookups.

Measured with 'git worktree add --detach --no-checkout' on a repository
with 200 existing linked worktrees (median of seven runs per version,
warm caches):

              before     after
files         11.13 ms    6.77 ms
reftable      18.86 ms    7.60 ms

Signed-off-by: Maik Riechert <letmaik@outlook.com>
---
    worktree add: skip HEAD reads for destination checks
    
    Changes since v1:
    
    Reworded the benchmark introduction as suggested by Junio. No code
    changes.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2339%2Fletmaik%2Fworktree-add-path-checks-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2339/letmaik/worktree-add-path-checks-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2339

Range-diff vs v1:

 1:  17946461ad ! 1:  054d208b66 worktree add: skip HEAD reads for destination checks
     @@ Commit message
          Use get_worktrees_without_reading_head() for the destination check to
          avoid these unnecessary lookups.
      
     -    Detached git worktree add --no-checkout with 200 existing linked
     -    worktrees. Median of seven runs per version, with warm caches:
     +    Measured with 'git worktree add --detach --no-checkout' on a repository
     +    with 200 existing linked worktrees (median of seven runs per version,
     +    warm caches):
      
                        before     after
          files         11.13 ms    6.77 ms


 builtin/worktree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index 77ecd0f71f..82a93b0adf 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -473,7 +473,7 @@ static int add_worktree(const char *path, const char *refname,
 	struct ref_store *wt_refs;
 	struct repo_config_values *cfg = repo_config_values(the_repository);
 
-	worktrees = get_worktrees(the_repository);
+	worktrees = get_worktrees_without_reading_head(the_repository);
 	check_candidate_path(path, opts->force, worktrees, "add");
 	free_worktrees(worktrees);
 	worktrees = NULL;

base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
-- 
gitgitgadget
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads