Skip to content

Commit 312cff5

Browse files
ttaylorrgitster
authored andcommitted
bloom: split 'get_bloom_filter()' in two
'get_bloom_filter' takes a flag to control whether it will compute a Bloom filter if the requested one is missing. In the next patch, we'll add yet another parameter to this method, which would force all but one caller to specify an extra 'NULL' parameter at the end. Instead of doing this, split 'get_bloom_filter' into two functions: 'get_bloom_filter' and 'get_or_compute_bloom_filter'. The former only looks up a Bloom filter (and does not compute one if it's missing, thus dropping the 'compute_if_not_present' flag). The latter does compute missing Bloom filters, with an additional parameter to store whether or not it needed to do so. This simplifies many call-sites, since the majority of existing callers to 'get_bloom_filter' do not want missing Bloom filters to be computed (so they can drop the parameter entirely and use the simpler version of the function). While we're at it, instrument the new 'get_or_compute_bloom_filter()' with counters in the 'write_commit_graph_context' struct which store the number of filters that we did and didn't compute, as well as filters that were truncated. It would be nice to drop the 'compute_if_not_present' flag entirely, since all remaining callers of 'get_or_compute_bloom_filter' pass it as '1', but this will change in a future patch and hence cannot be removed. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 97ffa4f commit 312cff5

File tree

7 files changed

+62
-13
lines changed

7 files changed

+62
-13
lines changed

blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ static int maybe_changed_path(struct repository *r,
12751275
if (commit_graph_generation(origin->commit) == GENERATION_NUMBER_INFINITY)
12761276
return 1;
12771277

1278-
filter = get_bloom_filter(r, origin->commit, 0);
1278+
filter = get_bloom_filter(r, origin->commit);
12791279

12801280
if (!filter)
12811281
return 1;

bloom.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,20 @@ static int pathmap_cmp(const void *hashmap_cmp_fn_data,
177177
return strcmp(e1->path, e2->path);
178178
}
179179

180-
struct bloom_filter *get_bloom_filter(struct repository *r,
181-
struct commit *c,
182-
int compute_if_not_present)
180+
struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
181+
struct commit *c,
182+
int compute_if_not_present,
183+
enum bloom_filter_computed *computed)
183184
{
184185
struct bloom_filter *filter;
185186
struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS;
186187
int i;
187188
struct diff_options diffopt;
188189
int max_changes = 512;
189190

191+
if (computed)
192+
*computed = BLOOM_NOT_COMPUTED;
193+
190194
if (!bloom_filters.slab_size)
191195
return NULL;
192196

@@ -271,8 +275,14 @@ struct bloom_filter *get_bloom_filter(struct repository *r,
271275
diff_free_filepair(diff_queued_diff.queue[i]);
272276
filter->data = NULL;
273277
filter->len = 0;
278+
279+
if (computed)
280+
*computed |= BLOOM_TRUNC_LARGE;
274281
}
275282

283+
if (computed)
284+
*computed |= BLOOM_COMPUTED;
285+
276286
free(diff_queued_diff.queue);
277287
DIFF_QUEUE_CLEAR(&diff_queued_diff);
278288

bloom.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,19 @@ void add_key_to_filter(const struct bloom_key *key,
8989

9090
void init_bloom_filters(void);
9191

92-
struct bloom_filter *get_bloom_filter(struct repository *r,
93-
struct commit *c,
94-
int compute_if_not_present);
92+
enum bloom_filter_computed {
93+
BLOOM_NOT_COMPUTED = (1 << 0),
94+
BLOOM_COMPUTED = (1 << 1),
95+
BLOOM_TRUNC_LARGE = (1 << 2),
96+
};
97+
98+
struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
99+
struct commit *c,
100+
int compute_if_not_present,
101+
enum bloom_filter_computed *computed);
102+
103+
#define get_bloom_filter(r, c) get_or_compute_bloom_filter( \
104+
(r), (c), 0, NULL)
95105

96106
int bloom_filter_contains(const struct bloom_filter *filter,
97107
const struct bloom_key *key,

commit-graph.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,10 @@ struct write_commit_graph_context {
965965
const struct split_commit_graph_opts *split_opts;
966966
size_t total_bloom_filter_data_size;
967967
const struct bloom_filter_settings *bloom_settings;
968+
969+
int count_bloom_filter_computed;
970+
int count_bloom_filter_not_computed;
971+
int count_bloom_filter_trunc_large;
968972
};
969973

970974
static int write_graph_chunk_fanout(struct hashfile *f,
@@ -1176,7 +1180,7 @@ static int write_graph_chunk_bloom_indexes(struct hashfile *f,
11761180
uint32_t cur_pos = 0;
11771181

11781182
while (list < last) {
1179-
struct bloom_filter *filter = get_bloom_filter(ctx->r, *list, 0);
1183+
struct bloom_filter *filter = get_bloom_filter(ctx->r, *list);
11801184
size_t len = filter ? filter->len : 0;
11811185
cur_pos += len;
11821186
display_progress(ctx->progress, ++ctx->progress_cnt);
@@ -1216,7 +1220,7 @@ static int write_graph_chunk_bloom_data(struct hashfile *f,
12161220
hashwrite_be32(f, ctx->bloom_settings->bits_per_entry);
12171221

12181222
while (list < last) {
1219-
struct bloom_filter *filter = get_bloom_filter(ctx->r, *list, 0);
1223+
struct bloom_filter *filter = get_bloom_filter(ctx->r, *list);
12201224
size_t len = filter ? filter->len : 0;
12211225

12221226
display_progress(ctx->progress, ++ctx->progress_cnt);
@@ -1386,6 +1390,16 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
13861390
stop_progress(&ctx->progress);
13871391
}
13881392

1393+
static void trace2_bloom_filter_write_statistics(struct write_commit_graph_context *ctx)
1394+
{
1395+
trace2_data_intmax("commit-graph", ctx->r, "filter-computed",
1396+
ctx->count_bloom_filter_computed);
1397+
trace2_data_intmax("commit-graph", ctx->r, "filter-not-computed",
1398+
ctx->count_bloom_filter_not_computed);
1399+
trace2_data_intmax("commit-graph", ctx->r, "filter-trunc-large",
1400+
ctx->count_bloom_filter_trunc_large);
1401+
}
1402+
13891403
static void compute_bloom_filters(struct write_commit_graph_context *ctx)
13901404
{
13911405
int i;
@@ -1408,12 +1422,26 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
14081422
QSORT(sorted_commits, ctx->commits.nr, commit_gen_cmp);
14091423

14101424
for (i = 0; i < ctx->commits.nr; i++) {
1425+
enum bloom_filter_computed computed = 0;
14111426
struct commit *c = sorted_commits[i];
1412-
struct bloom_filter *filter = get_bloom_filter(ctx->r, c, 1);
1427+
struct bloom_filter *filter = get_or_compute_bloom_filter(
1428+
ctx->r,
1429+
c,
1430+
1,
1431+
&computed);
1432+
if (computed & BLOOM_COMPUTED) {
1433+
ctx->count_bloom_filter_computed++;
1434+
if (computed & BLOOM_TRUNC_LARGE)
1435+
ctx->count_bloom_filter_trunc_large++;
1436+
} else if (computed & BLOOM_NOT_COMPUTED)
1437+
ctx->count_bloom_filter_not_computed++;
14131438
ctx->total_bloom_filter_data_size += sizeof(unsigned char) * filter->len;
14141439
display_progress(progress, i + 1);
14151440
}
14161441

1442+
if (trace2_is_enabled())
1443+
trace2_bloom_filter_write_statistics(ctx);
1444+
14171445
free(sorted_commits);
14181446
stop_progress(&progress);
14191447
}

line-log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ static int bloom_filter_check(struct rev_info *rev,
11591159
return 1;
11601160

11611161
if (!rev->bloom_filter_settings ||
1162-
!(filter = get_bloom_filter(rev->repo, commit, 0)))
1162+
!(filter = get_bloom_filter(rev->repo, commit)))
11631163
return 1;
11641164

11651165
if (!range)

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
753753
if (commit_graph_generation(commit) == GENERATION_NUMBER_INFINITY)
754754
return -1;
755755

756-
filter = get_bloom_filter(revs->repo, commit, 0);
756+
filter = get_bloom_filter(revs->repo, commit);
757757

758758
if (!filter) {
759759
count_bloom_filter_not_present++;

t/helper/test-bloom.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static void get_bloom_filter_for_commit(const struct object_id *commit_oid)
3939
struct bloom_filter *filter;
4040
setup_git_directory();
4141
c = lookup_commit(the_repository, commit_oid);
42-
filter = get_bloom_filter(the_repository, c, 1);
42+
filter = get_or_compute_bloom_filter(the_repository, c, 1,
43+
NULL);
4344
print_bloom_filter(filter);
4445
}
4546

0 commit comments

Comments
 (0)