From: Phillip Wood Date: Thu, 23 Apr 2026 15:15:51 GMT Subject: Re: [PATCH v2 2/3] builtin/log: prefetch necessary blobs for `git cherry` Message-ID: <2abdc8ba-e361-492c-88b7-0c807ee9fb4d@gmail.com> In-Reply-To: Hi Elijah On 21/04/2026 22:28, Elijah Newren wrote: > On Sun, Apr 19, 2026 at 7:04 AM Phillip Wood wrote: >> On 18/04/2026 01:32, Elijah Newren via GitGitGadget wrote: >>> From: Elijah Newren >>> >>> In partial clones, `git cherry` fetches necessary blobs on-demand one >>> at a time, which can be very slow. We would like to prefetch all >>> necessary blobs upfront. To do so, we need to be able to first figure >>> out which blobs are needed. >> >> "git rebase" without "--reapply-cherry-picks" suffers from this problem >> as well as it does the equivalent of "git log --cherry-pick". Is there >> any way to share prefetch_cherry_blobs() with the cherry-pick detection >> in revision.c? > > Yes, you're right; git rebase without --reapply-cherry-picks and git > log --cherry-pick both go through cherry_pick_list() in revision.c, > which has exactly the same shape as the patch-ids loop in > cmd_cherry(): build a hashmap of one side via add_commit_patch_id(), > then look up the other side via patch_id_iter_first(). The on-demand > blob fetches come from the same patch_id_neq() callback. > > After poking around, I think the approximate scope of the fix would > be: Move collect_diff_blob_oids(), always_match(), and > prefetch_cherry_blobs() from builtin/log.c to patch-ids.c and expose > the last one in patch-ids.h. In cherry_pick_list(), between the > add_commit_patch_id loop and the comparison loop, build a temporary > list of just the lookup-side commits (filtering by > SYMMETRIC_LEFT/BOUNDARY as the existing loop already does) and call > prefetch_cherry_blobs() on it. Thanks for taking a look > That said, I'd rather leave this out of the current series. The bigger > picture is that I have reservations about expanding partial-clone > support further into this area. git cherry, git log --cherry-pick, and > the default cherry-pick detection in git rebase all exist to answer > "has this patch already landed upstream?" -- a question that, in > repositories large enough to need partial clones, I feel is rarely > worth the cost of computing patch-ids across arbitrary amounts of > history. The honest guidance I would probably give for users on a > large repo is "pass --reapply-cherry-picks (with rebase) and skip this > entirely" or to narrow the range under consideration. "--reapply-cherry-picks --empty=drop" is certainly more efficient. When we're computing patch ids do we do it for every upstream commit or just the ones that modify the set of paths that are modified in the branch we're rebasing? It is a shame that we don't have a config setting for "-reapply-cherry-picks" as it is easy to forget to pass that option. Unfortunately it is not supported by the apply backend which makes such a setting potentially confusing. > The omission of > a --no-reapply-cherry-picks option in git-replay wasn't a lack of > effort or oversight, but a deliberate choice where I'd rather hold off > (possibly indefinitely) on implementing it. So I'm a bit reluctant to > make the performance hazard less visible without also asking whether > we should even be doing that piece of the operation. > > I only implemented the git cherry fix because of a specific customer > situation where the operation was already baked into tooling, and > prefetching at least makes the worst case tolerable. I'm a bit surprised customers aren't complaining about tools that use "git rebase" being slow. > I don't want to > hold myself to doing the same for the cherry_pick_list() path, but I'm > fairly confident the code here can be re-used for those other cases > and I'd help review a patch from anyone who wants to carry it forward. > > Anyway, you are making the right connection, it's just that my > personal answer is to let some other interested individual do it. Fair enough Thanks Phillip