summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
authorAbhishek Kumar <abhishekkumar8222@gmail.com>2020-06-17 09:14:09 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-06-17 21:37:23 (GMT)
commit4844812b9ec9bc6ffdc2da2c54d9146ff4c97d94 (patch)
treeb0df2ea1f12101e9ab2456820fc5b32a86db91ed /commit-graph.c
parent6da43d937ca96d277556fa92c5a664fb1cbcc8ac (diff)
downloadgit-4844812b9ec9bc6ffdc2da2c54d9146ff4c97d94.zip
git-4844812b9ec9bc6ffdc2da2c54d9146ff4c97d94.tar.gz
git-4844812b9ec9bc6ffdc2da2c54d9146ff4c97d94.tar.bz2
commit-graph: introduce commit_graph_data_slab
The struct commit is used in many contexts. However, members `generation` and `graph_pos` are only used for commit-graph related operations and otherwise waste memory. This wastage would have been more pronounced as we transition to generation number v2, which uses 64-bit generation number instead of current 32-bits. As they are often accessed together, let's introduce struct commit_graph_data and move them to a commit_graph_data slab. While the overall test suite runs just as fast as master, (series: 26m48s, master: 27m34s, faster by 2.87%), certain commands like `git merge-base --is-ancestor` were slowed by 40% as discovered by Szeder Gábor [1]. After minimizing commit-slab access, the slow down persists but is closer to 20%. Derrick Stolee believes the slow down is attributable to the underlying algorithm rather than the slowness of commit-slab access [2] and we will follow-up in a later series. [1]: https://lore.kernel.org/git/20200607195347.GA8232@szeder.dev/ [2]: https://lore.kernel.org/git/13db757a-9412-7f1e-805c-8a028c4ab2b1@gmail.com/ Signed-off-by: Abhishek Kumar <abhishekkumar8222@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c78
1 files changed, 68 insertions, 10 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 2ff042f..8ad7d20 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -87,6 +87,58 @@ static int commit_pos_cmp(const void *va, const void *vb)
commit_pos_at(&commit_pos, b);
}
+define_commit_slab(commit_graph_data_slab, struct commit_graph_data);
+static struct commit_graph_data_slab commit_graph_data_slab =
+ COMMIT_SLAB_INIT(1, commit_graph_data_slab);
+
+uint32_t commit_graph_position(const struct commit *c)
+{
+ struct commit_graph_data *data =
+ commit_graph_data_slab_peek(&commit_graph_data_slab, c);
+
+ return data ? data->graph_pos : COMMIT_NOT_FROM_GRAPH;
+}
+
+uint32_t commit_graph_generation(const struct commit *c)
+{
+ struct commit_graph_data *data =
+ commit_graph_data_slab_peek(&commit_graph_data_slab, c);
+
+ if (!data)
+ return GENERATION_NUMBER_INFINITY;
+ else if (data->graph_pos == COMMIT_NOT_FROM_GRAPH)
+ return GENERATION_NUMBER_INFINITY;
+
+ return data->generation;
+}
+
+static struct commit_graph_data *commit_graph_data_at(const struct commit *c)
+{
+ unsigned int i, nth_slab;
+ struct commit_graph_data *data =
+ commit_graph_data_slab_peek(&commit_graph_data_slab, c);
+
+ if (data)
+ return data;
+
+ nth_slab = c->index / commit_graph_data_slab.slab_size;
+ data = commit_graph_data_slab_at(&commit_graph_data_slab, c);
+
+ /*
+ * commit-slab initializes elements with zero, overwrite this with
+ * COMMIT_NOT_FROM_GRAPH for graph_pos.
+ *
+ * We avoid initializing generation with checking if graph position
+ * is not COMMIT_NOT_FROM_GRAPH.
+ */
+ for (i = 0; i < commit_graph_data_slab.slab_size; i++) {
+ commit_graph_data_slab.slab[nth_slab][i].graph_pos =
+ COMMIT_NOT_FROM_GRAPH;
+ }
+
+ return data;
+}
+
static int commit_gen_cmp(const void *va, const void *vb)
{
const struct commit *a = *(const struct commit **)va;
@@ -1020,7 +1072,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
else
packedDate[0] = 0;
- packedDate[0] |= htonl((*list)->generation << 2);
+ packedDate[0] |= htonl(commit_graph_data_at(*list)->generation << 2);
packedDate[1] = htonl((*list)->date);
hashwrite(f, packedDate, 8);
@@ -1251,9 +1303,11 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
_("Computing commit graph generation numbers"),
ctx->commits.nr);
for (i = 0; i < ctx->commits.nr; i++) {
+ uint32_t generation = commit_graph_data_at(ctx->commits.list[i])->generation;
+
display_progress(ctx->progress, i + 1);
- if (ctx->commits.list[i]->generation != GENERATION_NUMBER_INFINITY &&
- ctx->commits.list[i]->generation != GENERATION_NUMBER_ZERO)
+ if (generation != GENERATION_NUMBER_INFINITY &&
+ generation != GENERATION_NUMBER_ZERO)
continue;
commit_list_insert(ctx->commits.list[i], &list);
@@ -1264,22 +1318,26 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
uint32_t max_generation = 0;
for (parent = current->parents; parent; parent = parent->next) {
- if (parent->item->generation == GENERATION_NUMBER_INFINITY ||
- parent->item->generation == GENERATION_NUMBER_ZERO) {
+ generation = commit_graph_data_at(parent->item)->generation;
+
+ if (generation == GENERATION_NUMBER_INFINITY ||
+ generation == GENERATION_NUMBER_ZERO) {
all_parents_computed = 0;
commit_list_insert(parent->item, &list);
break;
- } else if (parent->item->generation > max_generation) {
- max_generation = parent->item->generation;
+ } else if (generation > max_generation) {
+ max_generation = generation;
}
}
if (all_parents_computed) {
- current->generation = max_generation + 1;
+ struct commit_graph_data *data = commit_graph_data_at(current);
+
+ data->generation = max_generation + 1;
pop_commit(&list);
- if (current->generation > GENERATION_NUMBER_MAX)
- current->generation = GENERATION_NUMBER_MAX;
+ if (data->generation > GENERATION_NUMBER_MAX)
+ data->generation = GENERATION_NUMBER_MAX;
}
}
}