Skip to content

worktree add: skip HEAD reads for destination checks - #2339

Open
letmaik wants to merge 1 commit into
gitgitgadget:masterfrom
letmaik:worktree-add-path-checks
Open

letmaik wants to merge 1 commit into
gitgitgadget:masterfrom
letmaik:worktree-add-path-checks

Conversation

@letmaik

@letmaik letmaik commented Nov 28, 2026 •

Copy link
Copy Markdown

Changes since v1:

Reworded the benchmark introduction as suggested by Junio. No code changes.

CC: Eric Sunshine sunshine@sunshineco.com, Patrick Steinhardt ps@pks.im

@letmaik

letmaik commented Nov 28, 2026

Copy link
Copy Markdown
Author

/submit

@gitgitgadget

gitgitgadget Bot commented Nov 28, 2026

Copy link
Copy Markdown

Submitted as pull.2339.git.1795907202117.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2339/letmaik/worktree-add-path-checks-v1

To fetch this version to local tag pr-2339/letmaik/worktree-add-path-checks-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2339/letmaik/worktree-add-path-checks-v1

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>
@letmaik
letmaik force-pushed the worktree-add-path-checks branch from 1794646 to 054d208 Compare November 29, 2026 05:38
@letmaik

letmaik commented Nov 29, 2026

Copy link
Copy Markdown
Author

/submit

@gitgitgadget

gitgitgadget Bot commented Nov 29, 2026

Copy link
Copy Markdown

Submitted as pull.2339.v2.git.1795930874388.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2339/letmaik/worktree-add-path-checks-v2

To fetch this version to local tag pr-2339/letmaik/worktree-add-path-checks-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2339/letmaik/worktree-add-path-checks-v2

@gitgitgadget

gitgitgadget Bot commented Nov 29, 2026

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"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 ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant