On Wed, Feb 3, 2021 at 3:44 AM Derrick Stolee [off-list ref] wrote:
On 2/3/2021 12:49 AM, Elijah Newren via GitGitGadget wrote:
quoted
From: Elijah Newren <redacted>
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.
...
quoted
+ 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.
quoted
/* 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.
quoted
- 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.
quoted
+ 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