Skip to content

Commit 582aa00

Browse files
René Scharfegitster
authored andcommitted
git diff too slow for a file
Ever since the xdiff library had been introduced to git, all its callers have used the flag XDF_NEED_MINIMAL. It makes sure that the smallest possible diff is produced, but that takes quite some time if there are lots of differences that can be expressed in multiple ways. This flag makes a difference for only 0.1% of the non-merge commits in the git repo of Linux, both in terms of diff size and execution time. The patches there are mostly nice and small. SungHyun Nam however reported a case in a different repo where a diff took more than 20 times longer to generate with XDF_NEED_MINIMAL than without. Rebasing became really slow. This patch removes this flag from all callers. The default of xdiff is saner because it has minimal to no impact in the normal case of small diffs and doesn't incur that much of a speed penalty for large ones. A follow-up patch may introduce a command line option to set the flag if the user needs it, similar to GNU diff's -d/--minimal. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ed215b1 commit 582aa00

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

builtin-blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static int show_root;
3939
static int reverse;
4040
static int blank_boundary;
4141
static int incremental;
42-
static int xdl_opts = XDF_NEED_MINIMAL;
42+
static int xdl_opts;
4343

4444
static enum date_mode blame_date_mode = DATE_ISO8601;
4545
static size_t blame_date_width;

builtin-merge-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
2525
const char *names[3] = { NULL, NULL, NULL };
2626
mmfile_t mmfs[3];
2727
mmbuffer_t result = {NULL, 0};
28-
xmparam_t xmp = {{XDF_NEED_MINIMAL}};
28+
xmparam_t xmp = {{0}};
2929
int ret = 0, i = 0, to_stdout = 0;
3030
int level = XDL_MERGE_ZEALOUS_ALNUM;
3131
int style = 0, quiet = 0;

builtin-merge-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void show_diff(struct merge_list *entry)
106106
xdemitconf_t xecfg;
107107
xdemitcb_t ecb;
108108

109-
xpp.flags = XDF_NEED_MINIMAL;
109+
xpp.flags = 0;
110110
memset(&xecfg, 0, sizeof(xecfg));
111111
xecfg.ctxlen = 3;
112112
ecb.outf = show_outf;

builtin-rerere.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static int diff_two(const char *file1, const char *label1,
8989
printf("--- a/%s\n+++ b/%s\n", label1, label2);
9090
fflush(stdout);
9191
memset(&xpp, 0, sizeof(xpp));
92-
xpp.flags = XDF_NEED_MINIMAL;
92+
xpp.flags = 0;
9393
memset(&xecfg, 0, sizeof(xecfg));
9494
xecfg.ctxlen = 3;
9595
ecb.outf = outf;

combine-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
221221
parent_file.ptr = grab_blob(parent, mode, &sz);
222222
parent_file.size = sz;
223223
memset(&xpp, 0, sizeof(xpp));
224-
xpp.flags = XDF_NEED_MINIMAL;
224+
xpp.flags = 0;
225225
memset(&xecfg, 0, sizeof(xecfg));
226226
memset(&state, 0, sizeof(state));
227227
state.nmask = nmask;

diff.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static void diff_words_show(struct diff_words_data *diff_words)
714714
memset(&xecfg, 0, sizeof(xecfg));
715715
diff_words_fill(&diff_words->minus, &minus, diff_words->word_regex);
716716
diff_words_fill(&diff_words->plus, &plus, diff_words->word_regex);
717-
xpp.flags = XDF_NEED_MINIMAL;
717+
xpp.flags = 0;
718718
/* as only the hunk header will be parsed, we need a 0-context */
719719
xecfg.ctxlen = 0;
720720
xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
@@ -1743,7 +1743,7 @@ static void builtin_diff(const char *name_a,
17431743
check_blank_at_eof(&mf1, &mf2, &ecbdata);
17441744
ecbdata.file = o->file;
17451745
ecbdata.header = header.len ? &header : NULL;
1746-
xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
1746+
xpp.flags = o->xdl_opts;
17471747
xecfg.ctxlen = o->context;
17481748
xecfg.interhunkctxlen = o->interhunkcontext;
17491749
xecfg.flags = XDL_EMIT_FUNCNAMES;
@@ -1833,7 +1833,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
18331833

18341834
memset(&xpp, 0, sizeof(xpp));
18351835
memset(&xecfg, 0, sizeof(xecfg));
1836-
xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
1836+
xpp.flags = o->xdl_opts;
18371837
xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
18381838
&xpp, &xecfg, &ecb);
18391839
}
@@ -1882,7 +1882,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
18821882
memset(&xpp, 0, sizeof(xpp));
18831883
memset(&xecfg, 0, sizeof(xecfg));
18841884
xecfg.ctxlen = 1; /* at least one context line */
1885-
xpp.flags = XDF_NEED_MINIMAL;
1885+
xpp.flags = 0;
18861886
xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data,
18871887
&xpp, &xecfg, &ecb);
18881888

@@ -3419,7 +3419,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
34193419
len2, p->two->path);
34203420
git_SHA1_Update(&ctx, buffer, len1);
34213421

3422-
xpp.flags = XDF_NEED_MINIMAL;
3422+
xpp.flags = 0;
34233423
xecfg.ctxlen = 3;
34243424
xecfg.flags = XDL_EMIT_FUNCNAMES;
34253425
xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,

merge-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int generate_common_file(mmfile_t *res, mmfile_t *f1, mmfile_t *f2)
6060
xdemitcb_t ecb;
6161

6262
memset(&xpp, 0, sizeof(xpp));
63-
xpp.flags = XDF_NEED_MINIMAL;
63+
xpp.flags = 0;
6464
memset(&xecfg, 0, sizeof(xecfg));
6565
xecfg.ctxlen = 3;
6666
xecfg.flags = XDL_EMIT_COMMON;

0 commit comments

Comments
 (0)