Skip to content

Commit b337398

Browse files
peffgitster
authored andcommitted
diff: avoid useless filespec population
builtin_diff calls fill_mmfile fairly early, which in turn calls diff_populate_filespec, which actually retrieves the file's blob contents into a buffer. Long ago, this was sensible as we would need to look at the blobs eventually. These days, however, we may not ever want those blobs if we end up using a textconv cache, and for large binary files (exactly the sort for which you might have a textconv cache), just retrieving the objects can be costly. This patch just pushes the fill_mmfile call a bit later, so we can avoid populating the filespec in some cases. There is one thing to note that looks like a bug but isn't. We push the fill_mmfile down into the first branch of a conditional. It seems like we would need it on the other branch, too, but we don't; fill_textconv does it for us (in fact, before this, we were just writing over the results of the fill_mmfile on that branch). Here's a timing sample on a commit with 45 changed jpgs and avis. The result is fully textconv cached, but we still wasted a lot of time just pulling the blobs from storage. The total size of the blobs (source and dest) is about 180M. [before] $ time git show >/dev/null real 0m0.352s user 0m0.148s sys 0m0.200s [after] $ time git show >/dev/null real 0m0.009s user 0m0.004s sys 0m0.004s And that's on a warm cache. On a cold cache, the "after" case is not much worse, but the "before" case has to do an extra 180M of I/O. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9bae1a commit b337398

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

diff.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,12 +1680,11 @@ static void builtin_diff(const char *name_a,
16801680
}
16811681
}
16821682

1683-
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
1684-
die("unable to read files to diff");
1685-
16861683
if (!DIFF_OPT_TST(o, TEXT) &&
1687-
( (diff_filespec_is_binary(one) && !textconv_one) ||
1688-
(diff_filespec_is_binary(two) && !textconv_two) )) {
1684+
( (!textconv_one && diff_filespec_is_binary(one)) ||
1685+
(!textconv_two && diff_filespec_is_binary(two)) )) {
1686+
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
1687+
die("unable to read files to diff");
16891688
/* Quite common confusing case */
16901689
if (mf1.size == mf2.size &&
16911690
!memcmp(mf1.ptr, mf2.ptr, mf1.size))

0 commit comments

Comments
 (0)