Skip to content

Commit e30c5ee

Browse files
abhishekkumar2718gitster
authored andcommitted
commit-graph: fix regression when computing Bloom filters
Before computing Bloom filters, the commit-graph machinery uses commit_gen_cmp to sort commits by generation order for improved diff performance. 3d11275 (commit-graph: examine commits by generation number, 2020-03-30) claims that this sort can reduce the time spent to compute Bloom filters by nearly half. But since c49c82a (commit: move members graph_pos, generation to a slab, 2020-06-17), this optimization is broken, since asking for a 'commit_graph_generation()' directly returns GENERATION_NUMBER_INFINITY while writing. Not all hope is lost, though: 'commit_gen_cmp()' falls back to comparing commits by their date when they have equal generation number, and so since c49c82a is purely a date comparison function. This heuristic is good enough that we don't seem to loose appreciable performance while computing Bloom filters. Applying this patch (compared with v2.30.0) speeds up computing Bloom filters by factors ranging from 0.40% to 5.19% on various repositories [1]. So, avoid the useless 'commit_graph_generation()' while writing by instead accessing the slab directly. This returns the newly-computed generation numbers, and allows us to avoid the heuristic by directly comparing generation numbers. [1]: https://lore.kernel.org/git/[email protected]/ Signed-off-by: Abhishek Kumar <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71ca53e commit e30c5ee

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

commit-graph.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,17 @@ static struct commit_graph_data *commit_graph_data_at(const struct commit *c)
139139
return data;
140140
}
141141

142+
/*
143+
* Should be used only while writing commit-graph as it compares
144+
* generation value of commits by directly accessing commit-slab.
145+
*/
142146
static int commit_gen_cmp(const void *va, const void *vb)
143147
{
144148
const struct commit *a = *(const struct commit **)va;
145149
const struct commit *b = *(const struct commit **)vb;
146150

147-
uint32_t generation_a = commit_graph_generation(a);
148-
uint32_t generation_b = commit_graph_generation(b);
151+
uint32_t generation_a = commit_graph_data_at(a)->generation;
152+
uint32_t generation_b = commit_graph_data_at(b)->generation;
149153
/* lower generation commits first */
150154
if (generation_a < generation_b)
151155
return -1;

0 commit comments

Comments
 (0)