Skip to content

Commit 9975fc9

Browse files
szederderrickstolee
authored andcommitted
commit-graph: check all leading directories in changed path Bloom filters
The file 'dir/subdir/file' can only be modified if its leading directories 'dir' and 'dir/subdir' are modified as well. So when checking modified path Bloom filters looking for commits modifying a path with multiple path components, then check not only the full path in the Bloom filters, but all its leading directories as well. Take care to check these paths in "deepest first" order, because it's the full path that is least likely to be modified, and the Bloom filter queries can short circuit sooner. This can significantly reduce the average false positive rate, by about an order of magnitude or three(!), and can further speed up pathspec-limited revision walks. The table below compares the average false positive rate and runtime of git rev-list HEAD -- "$path" before and after this change for 5000+ randomly* selected paths from each repository: Average false Average Average positive rate runtime runtime before after before after difference ------------------------------------------------------------------ git 3.220% 0.7853% 0.0558s 0.0387s -30.6% linux 2.453% 0.0296% 0.1046s 0.0766s -26.8% tensorflow 2.536% 0.6977% 0.0594s 0.0420s -29.2% *Path selection was done with the following pipeline: git ls-tree -r --name-only HEAD | sort -R | head -n 5000 The improvements in runtime are much smaller than the improvements in average false positive rate, as we are clearly reaching diminishing returns here. However, all these timings depend on that accessing tree objects is reasonably fast (warm caches). If we had a partial clone and the tree objects had to be fetched from a promisor remote, e.g.: $ git clone --filter=tree:0 --bare file://.../webkit.git webkit.notrees.git $ git -C webkit.git -c core.modifiedPathBloomFilters=1 \ commit-graph write --reachable $ cp webkit.git/objects/info/commit-graph webkit.notrees.git/objects/info/ $ git -C webkit.notrees.git -c core.modifiedPathBloomFilters=1 \ rev-list HEAD -- "$path" then checking all leading path component can reduce the runtime from over an hour to a few seconds (and this is with the clone and the promisor on the same machine). This adjusts the tracing values in t4216-log-bloom.sh, which provides a concrete way to notice the improvement. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Derrick Stolee <[email protected]>
1 parent bdca834 commit 9975fc9

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

revision.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,10 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
670670
{
671671
struct pathspec_item *pi;
672672
char *path_alloc = NULL;
673-
const char *path;
673+
const char *path, *p;
674674
int last_index;
675-
int len;
675+
size_t len;
676+
int path_component_nr = 0, j;
676677

677678
if (!revs->commits)
678679
return;
@@ -705,8 +706,22 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
705706

706707
len = strlen(path);
707708

708-
revs->bloom_key = xmalloc(sizeof(struct bloom_key));
709-
fill_bloom_key(path, len, revs->bloom_key, revs->bloom_filter_settings);
709+
p = path;
710+
do {
711+
p = strchrnul(p + 1, '/');
712+
path_component_nr++;
713+
} while (p - path < len);
714+
715+
revs->bloom_keys_nr = path_component_nr;
716+
ALLOC_ARRAY(revs->bloom_keys, revs->bloom_keys_nr);
717+
718+
p = path;
719+
for (j = 0; j < revs->bloom_keys_nr; j++) {
720+
p = strchrnul(p + 1, '/');
721+
722+
fill_bloom_key(path, p - path, &revs->bloom_keys[j],
723+
revs->bloom_filter_settings);
724+
}
710725

711726
if (trace2_is_enabled() && !bloom_filter_atexit_registered) {
712727
atexit(trace2_bloom_filter_statistics_atexit);
@@ -720,7 +735,7 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
720735
struct commit *commit)
721736
{
722737
struct bloom_filter *filter;
723-
int result;
738+
int result = 1, j;
724739

725740
if (!revs->repo->objects->commit_graph)
726741
return -1;
@@ -740,9 +755,11 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
740755
return -1;
741756
}
742757

743-
result = bloom_filter_contains(filter,
744-
revs->bloom_key,
745-
revs->bloom_filter_settings);
758+
for (j = 0; result && j < revs->bloom_keys_nr; j++) {
759+
result = bloom_filter_contains(filter,
760+
&revs->bloom_keys[j],
761+
revs->bloom_filter_settings);
762+
}
746763

747764
if (result)
748765
count_bloom_filter_maybe++;
@@ -782,7 +799,7 @@ static int rev_compare_tree(struct rev_info *revs,
782799
return REV_TREE_SAME;
783800
}
784801

785-
if (revs->bloom_key && !nth_parent) {
802+
if (revs->bloom_keys_nr && !nth_parent) {
786803
bloom_ret = check_maybe_different_in_bloom_filter(revs, commit);
787804

788805
if (bloom_ret == 0)

revision.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ struct rev_info {
295295
struct topo_walk_info *topo_walk_info;
296296

297297
/* Commit graph bloom filter fields */
298-
/* The bloom filter key for the pathspec */
299-
struct bloom_key *bloom_key;
298+
/* The bloom filter key(s) for the pathspec */
299+
struct bloom_key *bloom_keys;
300+
int bloom_keys_nr;
301+
300302
/*
301303
* The bloom filter settings used to generate the key.
302304
* This is loaded from the commit-graph being used.

t/t4216-log-bloom.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ test_expect_success 'setup - add commit-graph to the chain with Bloom filters' '
142142

143143
test_bloom_filters_used_when_some_filters_are_missing () {
144144
log_args=$1
145-
bloom_trace_prefix="statistics:{\"filter_not_present\":3,\"zero_length_filter\":0,\"maybe\":8,\"definitely_not\":6"
145+
bloom_trace_prefix="statistics:{\"filter_not_present\":3,\"zero_length_filter\":0,\"maybe\":6,\"definitely_not\":8"
146146
setup "$log_args" &&
147147
grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" &&
148148
test_cmp log_wo_bloom log_w_bloom

0 commit comments

Comments
 (0)