git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] diffcore-rename: no point trying to find a match better than exact

From
Elijah Newren <newren@gmail.com>
Date
Feb 3, 2021, 16:31 UTC
Message-ID
<CABPp-BEvu1ZQ5X35dDU-Skd71ZNLWQjj9Ow2HVvdc=faSBkGiw@mail.gmail.com>
In-Reply-To
<515f55bd-90e2-9a7f-0973-501c9351969e@gmail.com>
On Wed, Feb 3, 2021 at 3:44 AM Derrick Stolee <stolee@gmail.com> wrote:
Show 22 quoted lines
>
> On 2/3/2021 12:49 AM, Elijah Newren via GitGitGadget wrote:
> > From: Elijah Newren <newren@gmail.com>
> >
> > diffcore_rename() had some code to avoid having destination paths that
> > already had an exact rename detected from being re-checked for other
> > renames.  Source paths, however, were re-checked because we wanted to
> > allow the possibility of detecting copies.  But if copy detection isn't
> > turned on, then this merely amounts to attempting to find a
> > better-than-exact match, which naturally ends up being an expensive
> > no-op.  In particular, copy detection is never turned on by the merge
> > machinery.
> ...
> > +     num_sources = rename_src_nr;
> > +     if (detect_rename != DIFF_DETECT_COPY)
> > +             num_sources -= rename_count;
>
> Ok, delete the renamed files from the sources. Using a new variable
> because rename_src_nr is actually a static global to diffcore-rename.c,
> describing the number of entries in the rename_src table. This is
> scary, but I think your new local is a good way to change the local
> logic of this method without adjusting that global.

I thought about changing rename_src, rename_src_nr, rename_dst, and rename_dst_nr to all be in some struct and make one of those on the stack locally in diffcore_rename() and then pass that structure around. Would be nice to get rid of more global state. But I've got enough things in the queue that I never made the jump.

Show 8 quoted lines
> >
> >       /* All done? */
> > -     if (!num_destinations)
> > +     if (!num_destinations || !num_sources)
> >               goto cleanup;
>
> And add an extra quit condition which is very possible to hit.
> Is it only hit when every "delete" is actually a rename?

Right, when every "delete" gets paired by exact rename detection to some "add" and is marked as a rename, meaning we have no more "deletes" to pair with anything. In later series, there will be additional reasons for num_sources to decrease and possibly hit 0.

Show 26 quoted lines
> > -     switch (too_many_rename_candidates(num_destinations, rename_src_nr,
> > +     switch (too_many_rename_candidates(num_destinations, num_sources,
> >                                          options)) {
>
> This is all about checking if we need to skip inexact renames. Makes
> sense to use the new number.
>
> > +                     if (one->rename_used &&
> > +                         detect_rename != DIFF_DETECT_COPY)
> > +                             continue;
> > +
>
> Have we "consumed" this input? Skip over it. Good. And this is inside
> a double-loop:
>
>         for (dst_cnt = i = 0; i < rename_dst_nr; i++) {
>                 ...
>                 for (j = 0; j < rename_src_nr; j++) {
>
> Keeping rename_src_nr in the inner loop makes sense, but this new
> 'continue;' gives most of the speedup, I imagine.
>
> This is a nice speedup for such a simple optimization.
>
> Thanks,
> -Stolee
Previous: Derrick StoleeNext: Junio C Hamano
Message 4 of 25 in “Optimization batch 6: make full use of exact renames”
  1. 0/2 Optimization batch 6: make full use of exact renamesElijah Newren via GitGitGadget, Feb 3, 2021
  2. 1/2 diffcore-rename: no point trying to find a match better than exactElijah Newren via GitGitGadget, Feb 3, 2021
  3. Derrick StoleeFeb 3, 2021
  4. Elijah NewrenFeb 3, 2021
  5. Junio C HamanoFeb 3, 2021
  6. Elijah NewrenFeb 3, 2021
  7. 2/2 diffcore-rename: filter rename_src list when possibleElijah Newren via GitGitGadget, Feb 3, 2021
  8. Junio C HamanoFeb 3, 2021
  9. Elijah NewrenFeb 3, 2021
  10. 0/2 Optimization batch 6: make full use of exact renamesElijah Newren via GitGitGadget, Feb 3, 2021
  11. 1/2 diffcore-rename: no point trying to find a match better than exactElijah Newren via GitGitGadget, Feb 3, 2021
  12. 2/2 diffcore-rename: filter rename_src list when possibleElijah Newren via GitGitGadget, Feb 3, 2021
  13. Junio C HamanoFeb 13, 2021
  14. Elijah NewrenFeb 13, 2021
  15. Junio C HamanoFeb 13, 2021
  16. Elijah NewrenFeb 13, 2021
  17. Junio C HamanoFeb 3, 2021
  18. Elijah NewrenFeb 3, 2021
  19. Junio C HamanoFeb 3, 2021
  20. Jeff KingFeb 3, 2021
  21. Elijah NewrenFeb 4, 2021
  22. 0/2 Optimization batch 6: make full use of exact renamesElijah Newren via GitGitGadget, Feb 14, 2021
  23. 1/2 diffcore-rename: no point trying to find a match better than exactElijah Newren via GitGitGadget, Feb 14, 2021
  24. 2/2 diffcore-rename: filter rename_src list when possibleElijah Newren via GitGitGadget, Feb 14, 2021
  25. Elijah NewrenFeb 3, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.