summaryrefslogtreecommitdiff
path: root/src/diff.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-01-03 16:07:36 +0000
committerPatrick Steinhardt <ps@pks.im>2018-01-03 16:28:24 +0000
commitd8896bda5c43616f3c755242703fce7c2a97ad67 (patch)
treebaf8df2499191627a6119aca81cd9223cada9e6d /src/diff.h
parent7610638ec829ffd6da6d5f74b5b14dbb32b74924 (diff)
downloadlibgit2-d8896bda5c43616f3c755242703fce7c2a97ad67.tar.gz
diff_generate: avoid excessive stats of .gitattribute files
When generating a diff between two trees, for each file that is to be diffed we have to determine whether it shall be treated as text or as binary files. While git has heuristics to determine which kind of diff to generate, users can also that default behaviour by setting or unsetting the 'diff' attribute for specific files. Because of that, we have to query gitattributes in order to determine how to diff the current files. Instead of hitting the '.gitattributes' file every time we need to query an attribute, which can get expensive especially on networked file systems, we try to cache them instead. This works perfectly fine for every '.gitattributes' file that is found, but we hit cache invalidation problems when we determine that an attribuse file is _not_ existing. We do create an entry in the cache for missing '.gitattributes' files, but as soon as we hit that file again we invalidate it and stat it again to see if it has now appeared. In the case of diffing large trees with each other, this behaviour is very suboptimal. For each pair of files that is to be diffed, we will repeatedly query every directory component leading towards their respective location for an attributes file. This leads to thousands or even hundreds of thousands of wasted syscalls. The attributes cache already has a mechanism to help in that scenario in form of the `git_attr_session`. As long as the same attributes session is still active, we will not try to re-query the gitmodules files at all but simply retain our currently cached results. To fix our problem, we can create a session at the top-most level, which is the initialization of the `git_diff` structure, and use it in order to look up the correct diff driver. As the `git_diff` structure is used to generate patches for multiple files at once, this neatly solves our problem by retaining the session until patches for all files have been generated. The fix has been tested with linux.git by calling `git_diff_tree_to_tree` and `git_diff_to_buf` with v4.10^{tree} and v4.14^{tree}. | time | .gitattributes stats without fix | 33.201s | 844614 with fix | 30.327s | 4441 While execution only improved by roughly 10%, the stat(3) syscalls for .gitattributes files decreased by 99.5%. The benchmarks were quite simple with best-of-three timings on Linux ext4 systems. One can assume that for network based file systems the performance gain will be a lot larger due to a much higher latency.
Diffstat (limited to 'src/diff.h')
-rw-r--r--src/diff.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/diff.h b/src/diff.h
index 4e5dd93da..8c04438fa 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -34,6 +34,7 @@ typedef enum {
struct git_diff {
git_refcount rc;
git_repository *repo;
+ git_attr_session attrsession;
git_diff_origin_t type;
git_diff_options opts;
git_vector deltas; /* vector of git_diff_delta */