Skip to content

Commit f15eb7c

Browse files
newrengitster
authored andcommitted
diffcore-rename: no point trying to find a match better than exact
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. For the testcases mentioned in commit 557ac03 ("merge-ort: begin performance work; instrument with trace2_region_* calls", 2020-10-28), this change improves the performance as follows: Before After no-renames: 14.263 s ± 0.053 s 14.119 s ± 0.101 s mega-renames: 5504.231 s ± 5.150 s 1802.044 s ± 0.828 s just-one-mega: 158.534 s ± 0.498 s 51.391 s ± 0.028 s Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f011795 commit f15eb7c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

diffcore-rename.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,11 @@ void diffcore_rename(struct diff_options *options)
463463
struct diff_score *mx;
464464
int i, j, rename_count, skip_unmodified = 0;
465465
int num_destinations, dst_cnt;
466+
int num_sources, want_copies;
466467
struct progress *progress = NULL;
467468

468469
trace2_region_enter("diff", "setup", options->repo);
470+
want_copies = (detect_rename == DIFF_DETECT_COPY);
469471
if (!minimum_score)
470472
minimum_score = DEFAULT_RENAME_SCORE;
471473

@@ -502,7 +504,7 @@ void diffcore_rename(struct diff_options *options)
502504
p->one->rename_used++;
503505
register_rename_src(p);
504506
}
505-
else if (detect_rename == DIFF_DETECT_COPY) {
507+
else if (want_copies) {
506508
/*
507509
* Increment the "rename_used" score by
508510
* one, to indicate ourselves as a user.
@@ -532,12 +534,15 @@ void diffcore_rename(struct diff_options *options)
532534
* files still remain as options for rename/copies!)
533535
*/
534536
num_destinations = (rename_dst_nr - rename_count);
537+
num_sources = rename_src_nr;
538+
if (!want_copies)
539+
num_sources -= rename_count;
535540

536541
/* All done? */
537-
if (!num_destinations)
542+
if (!num_destinations || !num_sources)
538543
goto cleanup;
539544

540-
switch (too_many_rename_candidates(num_destinations, rename_src_nr,
545+
switch (too_many_rename_candidates(num_destinations, num_sources,
541546
options)) {
542547
case 1:
543548
goto cleanup;
@@ -553,7 +558,7 @@ void diffcore_rename(struct diff_options *options)
553558
if (options->show_rename_progress) {
554559
progress = start_delayed_progress(
555560
_("Performing inexact rename detection"),
556-
(uint64_t)num_destinations * (uint64_t)rename_src_nr);
561+
(uint64_t)num_destinations * (uint64_t)num_sources);
557562
}
558563

559564
mx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_destinations),
@@ -573,6 +578,9 @@ void diffcore_rename(struct diff_options *options)
573578
struct diff_filespec *one = rename_src[j].p->one;
574579
struct diff_score this_src;
575580

581+
if (one->rename_used && !want_copies)
582+
continue;
583+
576584
if (skip_unmodified &&
577585
diff_unmodified_pair(rename_src[j].p))
578586
continue;
@@ -594,15 +602,15 @@ void diffcore_rename(struct diff_options *options)
594602
}
595603
dst_cnt++;
596604
display_progress(progress,
597-
(uint64_t)dst_cnt * (uint64_t)rename_src_nr);
605+
(uint64_t)dst_cnt * (uint64_t)num_sources);
598606
}
599607
stop_progress(&progress);
600608

601609
/* cost matrix sorted by most to least similar pair */
602610
STABLE_QSORT(mx, dst_cnt * NUM_CANDIDATE_PER_DST, score_compare);
603611

604612
rename_count += find_renames(mx, dst_cnt, minimum_score, 0);
605-
if (detect_rename == DIFF_DETECT_COPY)
613+
if (want_copies)
606614
rename_count += find_renames(mx, dst_cnt, minimum_score, 1);
607615
free(mx);
608616
trace2_region_leave("diff", "inexact renames", options->repo);

0 commit comments

Comments
 (0)