When computing renames, we cache the hash signatures for each of the potentially conflicting entries so that we do not need to repeatedly read the file and can at least halfway efficiently determine whether two files are similar enough to be deemed a rename. In order to make the hash signatures meaningful, we require at least four lines of data to be present, resulting in at least four different hashes that can be compared. Files that are deemed too small are not cached at all and will thus be repeatedly re-hashed, which is usually not a huge issue. The issue with above heuristic is in case a file does _not_ have at least four lines, where a line is anything separated by a consecutive run of "\n" or "\0" characters. For example "a\nb" is two lines, but "a\0\0b" is also just two lines. Taken to the extreme, a file that has megabytes of consecutive space- or NUL-only may also be deemed as too small and thus not get cached. As a result, we will repeatedly load its blob, calculate its hash signature just to finally throw it away as we notice it's not of any value. When you've got a comparitively big file that you compare against a big set of potentially renamed files, then the cost simply expodes. The issue can be trivially fixed by introducing negative cache entries. Whenever we determine that a given blob does not have a meaningful representation via a hash signature, we store this negative cache marker and will from then on not hash it again, but also ignore it as a potential rename target. This should help the "normal" case already where you have a lot of small files as rename candidates, but in the above scenario it's savings are extraordinarily high. To verify we do not hit the issue anymore with described solution, this commit adds a test that uses the exact same setup described above with one 50 megabyte blob of '\0' characters and 1000 other files that get renamed. Without the negative cache: $ time ./libgit2_clar -smerge::trees::renames::cache_recomputation >/dev/null real 11m48.377s user 11m11.576s sys 0m35.187s And with the negative cache: $ time ./libgit2_clar -smerge::trees::renames::cache_recomputation >/dev/null real 0m1.972s user 0m1.851s sys 0m0.118s So this represents a ~350-fold performance improvement, but it obviously depends on how many files you have and how big the blob is. The test number were chosen in a way that one will immediately notice as soon as the bug resurfaces.
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
allocators | Loading commit data... | |
hash | Loading commit data... | |
streams | Loading commit data... | |
transports | Loading commit data... | |
unix | Loading commit data... | |
win32 | Loading commit data... | |
xdiff | Loading commit data... | |
CMakeLists.txt | Loading commit data... | |
alloc.c | Loading commit data... | |
alloc.h | Loading commit data... | |
annotated_commit.c | Loading commit data... | |
annotated_commit.h | Loading commit data... | |
apply.c | Loading commit data... | |
apply.h | Loading commit data... | |
array.h | Loading commit data... | |
attr.c | Loading commit data... | |
attr.h | Loading commit data... | |
attr_file.c | Loading commit data... | |
attr_file.h | Loading commit data... | |
attrcache.c | Loading commit data... | |
attrcache.h | Loading commit data... | |
bitvec.h | Loading commit data... | |
blame.c | Loading commit data... | |
blame.h | Loading commit data... | |
blame_git.c | Loading commit data... | |
blame_git.h | Loading commit data... | |
blob.c | Loading commit data... | |
blob.h | Loading commit data... | |
branch.c | Loading commit data... | |
branch.h | Loading commit data... | |
buf_text.c | Loading commit data... | |
buf_text.h | Loading commit data... | |
buffer.c | Loading commit data... | |
buffer.h | Loading commit data... | |
cache.c | Loading commit data... | |
cache.h | Loading commit data... | |
cc-compat.h | Loading commit data... | |
checkout.c | Loading commit data... | |
checkout.h | Loading commit data... | |
cherrypick.c | Loading commit data... | |
clone.c | Loading commit data... | |
clone.h | Loading commit data... | |
commit.c | Loading commit data... | |
commit.h | Loading commit data... | |
commit_list.c | Loading commit data... | |
commit_list.h | Loading commit data... | |
common.h | Loading commit data... | |
config.c | Loading commit data... | |
config.h | Loading commit data... | |
config_backend.h | Loading commit data... | |
config_cache.c | Loading commit data... | |
config_entries.c | Loading commit data... | |
config_entries.h | Loading commit data... | |
config_file.c | Loading commit data... | |
config_mem.c | Loading commit data... | |
config_parse.c | Loading commit data... | |
config_parse.h | Loading commit data... | |
config_snapshot.c | Loading commit data... | |
crlf.c | Loading commit data... | |
date.c | Loading commit data... | |
delta.c | Loading commit data... | |
delta.h | Loading commit data... | |
describe.c | Loading commit data... | |
diff.c | Loading commit data... | |
diff.h | Loading commit data... | |
diff_driver.c | Loading commit data... | |
diff_driver.h | Loading commit data... | |
diff_file.c | Loading commit data... | |
diff_file.h | Loading commit data... | |
diff_generate.c | Loading commit data... | |
diff_generate.h | Loading commit data... | |
diff_parse.c | Loading commit data... | |
diff_parse.h | Loading commit data... | |
diff_print.c | Loading commit data... | |
diff_stats.c | Loading commit data... | |
diff_tform.c | Loading commit data... | |
diff_tform.h | Loading commit data... | |
diff_xdiff.c | Loading commit data... | |
diff_xdiff.h | Loading commit data... | |
errors.c | Loading commit data... | |
errors.h | Loading commit data... | |
features.h.in | Loading commit data... | |
fetch.c | Loading commit data... | |
fetch.h | Loading commit data... | |
fetchhead.c | Loading commit data... | |
fetchhead.h | Loading commit data... | |
filebuf.c | Loading commit data... | |
filebuf.h | Loading commit data... | |
filter.c | Loading commit data... | |
filter.h | Loading commit data... | |
futils.c | Loading commit data... | |
futils.h | Loading commit data... | |
global.c | Loading commit data... | |
global.h | Loading commit data... | |
graph.c | Loading commit data... | |
hash.c | Loading commit data... | |
hash.h | Loading commit data... | |
hashsig.c | Loading commit data... | |
ident.c | Loading commit data... | |
idxmap.c | Loading commit data... | |
idxmap.h | Loading commit data... | |
ignore.c | Loading commit data... | |
ignore.h | Loading commit data... | |
index.c | Loading commit data... | |
index.h | Loading commit data... | |
indexer.c | Loading commit data... | |
indexer.h | Loading commit data... | |
integer.h | Loading commit data... | |
iterator.c | Loading commit data... | |
iterator.h | Loading commit data... | |
khash.h | Loading commit data... | |
mailmap.c | Loading commit data... | |
mailmap.h | Loading commit data... | |
map.h | Loading commit data... | |
merge.c | Loading commit data... | |
merge.h | Loading commit data... | |
merge_driver.c | Loading commit data... | |
merge_driver.h | Loading commit data... | |
merge_file.c | Loading commit data... | |
message.c | Loading commit data... | |
message.h | Loading commit data... | |
mwindow.c | Loading commit data... | |
mwindow.h | Loading commit data... | |
net.c | Loading commit data... | |
net.h | Loading commit data... | |
netops.c | Loading commit data... | |
netops.h | Loading commit data... | |
notes.c | Loading commit data... | |
notes.h | Loading commit data... | |
object.c | Loading commit data... | |
object.h | Loading commit data... | |
object_api.c | Loading commit data... | |
odb.c | Loading commit data... | |
odb.h | Loading commit data... | |
odb_loose.c | Loading commit data... | |
odb_mempack.c | Loading commit data... | |
odb_pack.c | Loading commit data... | |
offmap.c | Loading commit data... | |
offmap.h | Loading commit data... | |
oid.c | Loading commit data... | |
oid.h | Loading commit data... | |
oidarray.c | Loading commit data... | |
oidarray.h | Loading commit data... | |
oidmap.c | Loading commit data... | |
oidmap.h | Loading commit data... | |
pack-objects.c | Loading commit data... | |
pack-objects.h | Loading commit data... | |
pack.c | Loading commit data... | |
pack.h | Loading commit data... | |
parse.c | Loading commit data... | |
parse.h | Loading commit data... | |
patch.c | Loading commit data... | |
patch.h | Loading commit data... | |
patch_generate.c | Loading commit data... | |
patch_generate.h | Loading commit data... | |
patch_parse.c | Loading commit data... | |
patch_parse.h | Loading commit data... | |
path.c | Loading commit data... | |
path.h | Loading commit data... | |
pathspec.c | Loading commit data... | |
pathspec.h | Loading commit data... | |
pool.c | Loading commit data... | |
pool.h | Loading commit data... | |
posix.c | Loading commit data... | |
posix.h | Loading commit data... | |
pqueue.c | Loading commit data... | |
pqueue.h | Loading commit data... | |
proxy.c | Loading commit data... | |
proxy.h | Loading commit data... | |
push.c | Loading commit data... | |
push.h | Loading commit data... | |
reader.c | Loading commit data... | |
reader.h | Loading commit data... | |
rebase.c | Loading commit data... | |
refdb.c | Loading commit data... | |
refdb.h | Loading commit data... | |
refdb_fs.c | Loading commit data... | |
refdb_fs.h | Loading commit data... | |
reflog.c | Loading commit data... | |
reflog.h | Loading commit data... | |
refs.c | Loading commit data... | |
refs.h | Loading commit data... | |
refspec.c | Loading commit data... | |
refspec.h | Loading commit data... | |
regexp.c | Loading commit data... | |
regexp.h | Loading commit data... | |
remote.c | Loading commit data... | |
remote.h | Loading commit data... | |
repo_template.h | Loading commit data... | |
repository.c | Loading commit data... | |
repository.h | Loading commit data... | |
reset.c | Loading commit data... | |
revert.c | Loading commit data... | |
revparse.c | Loading commit data... | |
revwalk.c | Loading commit data... | |
revwalk.h | Loading commit data... | |
settings.c | Loading commit data... | |
signature.c | Loading commit data... | |
signature.h | Loading commit data... | |
sortedcache.c | Loading commit data... | |
sortedcache.h | Loading commit data... | |
stash.c | Loading commit data... | |
status.c | Loading commit data... | |
status.h | Loading commit data... | |
stream.h | Loading commit data... | |
strmap.c | Loading commit data... | |
strmap.h | Loading commit data... | |
strnlen.h | Loading commit data... | |
submodule.c | Loading commit data... | |
submodule.h | Loading commit data... | |
sysdir.c | Loading commit data... | |
sysdir.h | Loading commit data... | |
tag.c | Loading commit data... | |
tag.h | Loading commit data... | |
thread-utils.c | Loading commit data... | |
thread-utils.h | Loading commit data... | |
trace.c | Loading commit data... | |
trace.h | Loading commit data... | |
trailer.c | Loading commit data... | |
transaction.c | Loading commit data... | |
transaction.h | Loading commit data... | |
transport.c | Loading commit data... | |
tree-cache.c | Loading commit data... | |
tree-cache.h | Loading commit data... | |
tree.c | Loading commit data... | |
tree.h | Loading commit data... | |
tsort.c | Loading commit data... | |
userdiff.h | Loading commit data... | |
util.c | Loading commit data... | |
util.h | Loading commit data... | |
varint.c | Loading commit data... | |
varint.h | Loading commit data... | |
vector.c | Loading commit data... | |
vector.h | Loading commit data... | |
wildmatch.c | Loading commit data... | |
wildmatch.h | Loading commit data... | |
worktree.c | Loading commit data... | |
worktree.h | Loading commit data... | |
zstream.c | Loading commit data... | |
zstream.h | Loading commit data... |