Git development
 help / color / mirror / Atom feed
From: "Maik Riechert via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	Patrick Steinhardt <ps@pks.im>,
	Maik Riechert <letmaik@outlook.com>,
	Maik Riechert <letmaik@outlook.com>
Subject: [PATCH v2] worktree add: skip HEAD reads for destination checks
Date: Sun, 29 Nov 2026 05:41:14 +0000	[thread overview]
Message-ID: <pull.2339.v2.git.1795930874388.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2339.git.1795907202117.gitgitgadget@gmail.com>

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

      parent reply	other threads:[~2026-11-29  5:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 23:06 [PATCH] worktree add: skip HEAD reads for destination checks Maik Riechert via GitGitGadget
2026-11-29  5:01 ` Junio C Hamano
2026-11-29  5:41 ` Maik Riechert via GitGitGadget [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.2339.v2.git.1795930874388.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=letmaik@outlook.com \
    --cc=ps@pks.im \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox