Re: [PATCH 1/2] diffcore-rename: no point trying to find a match better than exact
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Feb 3, 2021, 11:44 UTC
- Message-ID
- <515f55bd-90e2-9a7f-0973-501c9351969e@gmail.com>
- In-Reply-To
- <3e69857f37e12540f7986245b99916b68702217a.1612331345.git.gitgitgadget@gmail.com>
On 2/3/2021 12:49 AM, Elijah Newren via GitGitGadget wrote:
Show 10 quoted lines
> 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.
Show 5 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?
> - 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