From: Wyatt Holden <wyattj.holden@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Wyatt Holden via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, stolee@gmail.com,
Wyatt Holden <wyattholden@microsoft.com>
Subject: Re: [PATCH 1/3] checkout: make orphaned commit checks configurable
Date: Wed, 2 Dec 2026 14:36:26 -0800 [thread overview]
Message-ID: <58366597-b3d0-4fd2-9ae5-2cfe1df8dfdc@gmail.com> (raw)
In-Reply-To: <CA+cX-GfrrYya++4Fyw2Fp1nX-EteD2_JfNs+FT8A_qegn-gbog@mail.gmail.com>
Hi Junio, thank you so much for taking a look. My previous email
responding to your feedback wasn't in plain text mode. Sorry about that.
Here's what I sent over -
> What factors are involved in making this
> "orphaned commits" check more expensive? The total number of
> branches? The length of commit chain we are leaving behind?
> So, in short, the answer to my earlier question is "we don't know".
Yes, we haven't separated the cost of ref enumeration from history
traversal in the affected repository. The stack samples at roughly
15, 45, and 75 seconds showed loose-ref filesystem operations inside
orphaned_commit_warning(). Skipping the routine with --quiet reduced
the observed checkout time from about 204 seconds to 14 seconds.
That points to ref enumeration as a contributor, but doesn't tell us
how much of the total time it accounts for. I wouldn't want to rule
out improving the check based on those observations. The opt-out
would let callers that don't need the warning avoid the work, while
leaving the default behavior unchanged for ordinary Git users.
> I am not sure how justifiable the design decision to leave the
> command line option out is.
Yeah, I agree. I initially intended the configuration setting for persistent
use and git -c for individual invocations, but a dedicated option is
more convenient and follows the status.aheadBehind precedent more
closely.
I've added --[no-]orphaned-commit-warning for both checkout
and switch. It overrides checkout.orphanedCommitWarning, so users can
also enable the check for an individual invocation when Scalar has
disabled it. --quiet retains its existing behavior of skipping the
check. I'll include the option, documentation, and tests in v2.
> But for human users, what are they losing by passing "-q" when they
> do not want to pay the cost of this check because we are not giving
> them an easy to use command line option? What other output are they
> declining by "--quiet"? "The following paths have local changes"
> list? Anything else?
Yes, the local change summary, along with the previous HEAD
description, branch-switch/reset messages, the new HEAD description
when detaching, and upstream tracking information.
For our automated runs, the output is also useful to people
inspecting the logs, even though the automation itself doesn't
consume it.
There is a qualification to the progress argument: --quiet --progress
can restore progress reporting. Retaining progress alone therefore
isn't sufficient justification for the option. The targeted opt-out
lets callers retain the other feedback as well.
> Another thing I noticed is that the loop in suggest_reattach() stops
> showing each commit after showing ORPHAN_CUTOFF but keeps counting.
> I wonder if it becomes palatable to introduce a configuration to
> stop it early, instead of disabling the orphaned_commit_warning()
> altogether?
Thanks, that seems worth exploring, especially if we can keep a
useful warning while reducing the cost.
Looking through the code, I noticed that ref enumeration happens
before suggest_reattach(). The UNINTERESTING commits supplied to
the walk also cause prepare_revision_walk() to run limit_list(),
so reachability traversal happens before the counting loop begins.
That makes me unsure how much stopping the counting loop early
would save in this case, particularly given the ref enumeration
seen in the stack samples. I'd like to measure those parts
separately to understand where an early exit would help most.
Would it make sense to keep the opt-out in this series and explore
a bounded check as a follow-up? That could preserve the warning
for users who want it, while callers that don't need it could
still skip the work entirely.
Thanks again for the thoughtful review and the encouraging
comments :)
Wyatt
On Tue, Nov 10, 2026 at 2:05 PM Junio C Hamano <gitster@pobox.com> wrote:
"Wyatt Holden via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Wyatt Holden <wyattholden@microsoft.com>
>
> When leaving a detached HEAD, checkout enumerates refs and walks
> history to warn about commits left behind. This work can dominate
> checkout time even after the working tree has been updated.
Interesting.
I often am on a detached HEAD but never realized this particular
check was expensive. The size of changes between the HEAD and the
next branch would affect the time it needs to update the working
tree (the larger the difference, the more expensive to complete the
branch switching). What factors are involved in making this
"orphaned commits" check more expensive? The total number of
branches? The length of commit chain we are leaving behind? I am
trying to see if this is something we can aim to optimize or if it
is a lost cause and a cop-out to introduce an option to disable the
check altogether is the best we can do.
> In an automated checkout of an internal monorepo, unpack_trees ended
> about 12 seconds into a roughly 204-second run. Stack dumps captured
> the main thread in orphaned_commit_warning(), enumerating loose refs
> and opening ref files. Using --quiet reduced the observed checkout
> time to about 14 seconds, but also suppressed unrelated output.
> These observations motivate an opt-out; they do not establish how
> much of the delay came from enumeration versus history traversal.
So, in short, the answer to my earlier question is "we don't know".
> Add checkout.orphanedCommitWarning, enabled by default, so checkout
> and switch can skip the check while retaining normal checkout output.
> Automated callers can opt out when they do not need a warning about
> leaving detached commits behind.
Sounds sensible.
> Follow the configuration precedent of 06b324c1d71 (status: add
> status.aheadbehind setting, 2019-06-18). Unlike status, introduce no
> dedicated command-line option; callers can use git -c for a one-off
> override.
I am not sure how justifiable the design decision to leave the
command line option out is.
The automation can run with "-q" to omit the overhead altogether, as
well as squelching any other output the automation would not read
anyway, so I would not worry too much about them.
But for human users, what are they losing by passing "-q" when they
do not want to pay the cost of this check because we are not giving
them an easy to use command line option? What other output are they
declining by "--quiet"? "The following paths have local changes"
list? Anything else?
> Add a Trace2 region around the check to make its cost visible in
> future investigations and to verify that disabling the setting skips
> the routine rather than merely hiding its warning. Document the
> setting and test both checkout and switch.
Sounds sensible.
> @@ -1132,6 +1134,7 @@ static void orphaned_commit_warning(struct
commit *old_commit, struct commit *ne
> struct rev_info revs;
> struct object *object = &old_commit->object;
>
> + trace2_region_enter("checkout", "orphaned_commit_warning",
the_repository);
> repo_init_revisions(the_repository, &revs, NULL);
> setup_revisions(0, NULL, &revs, NULL);
>
> @@ -1155,6 +1158,7 @@ static void orphaned_commit_warning(struct
commit *old_commit, struct commit *ne
> /* Clean up objects used, as they will be reused. */
> repo_clear_commit_marks(the_repository, ALL_REV_FLAGS);
> release_revisions(&revs);
> + trace2_region_leave("checkout", "orphaned_commit_warning",
the_repository);
> }
Quite straightforward. There is no early return in the middle, so
entering at the beginning with leaving at the end is the only change
necessary.
> @@ -1253,8 +1257,14 @@ static int switch_branches(const struct
checkout_opts *opts,
> }
> }
>
> - if (!opts->quiet && !old_branch_info.path &&
old_branch_info.commit && new_branch_info->commit !=
old_branch_info.commit)
> - orphaned_commit_warning(old_branch_info.commit,
new_branch_info->commit);
> + if (!opts->quiet && !old_branch_info.path &&
old_branch_info.commit &&
> + new_branch_info->commit != old_branch_info.commit) {
> + if (opts->orphaned_commit_warning)
> + orphaned_commit_warning(old_branch_info.commit,
new_branch_info->commit);
> + else
> + describe_detached_head(_("Previous HEAD
position was"),
> + old_branch_info.commit);
> + }
OK. The call into suggest_reattach() via orphaned_commit_warning()
is the more expensive part, and it also is where "Previous HEAD
was" comes, which we do not want to lose. It makes sense.
Another thing I noticed is that the loop in suggest_reattach() stops
showing each commit after showing ORPHAN_CUTOFF but keeps counting.
I wonder if it becomes palatable to introduce a configuration to
stop it early, instead of disabling the orphaned_commit_warning()
altogether?
next prev parent reply other threads:[~2026-12-02 22:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 19:11 [PATCH 0/3] Make orphaned commit checks configurable Wyatt Holden via GitGitGadget
2026-11-10 19:11 ` [PATCH 1/3] checkout: make " Wyatt Holden via GitGitGadget
2026-11-10 22:05 ` Junio C Hamano
[not found] ` <CA+cX-GfrrYya++4Fyw2Fp1nX-EteD2_JfNs+FT8A_qegn-gbog@mail.gmail.com>
2026-12-02 22:36 ` Wyatt Holden [this message]
2026-11-10 19:11 ` [PATCH 2/3] checkout: advise when orphaned commit checks are slow Wyatt Holden via GitGitGadget
2026-11-10 20:48 ` Derrick Stolee
2026-11-10 22:22 ` Junio C Hamano
2026-11-11 18:52 ` Junio C Hamano
2026-11-10 19:12 ` [PATCH 3/3] scalar: disable orphaned commit checks by default Wyatt Holden via GitGitGadget
2026-11-10 20:57 ` [PATCH 0/3] Make orphaned commit checks configurable Derrick Stolee
2026-11-10 22:29 ` Junio C Hamano
2026-12-02 21:45 ` Junio C Hamano
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=58366597-b3d0-4fd2-9ae5-2cfe1df8dfdc@gmail.com \
--to=wyattj.holden@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=stolee@gmail.com \
--cc=wyattholden@microsoft.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