pack-objects: move tree_depth into 'struct packing_data'

This reduces the size of 'struct object_entry' and therefore makes packing objects more efficient. This also renames cmp_tree_depth() into tree_depth_compare(), as it is more modern to have the name of the compare functions end with "compare". Helped-by: Jeff King <peff@peff.net> Helped-by: Duy Nguyen <pclouds@gmail.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Aug 16, 2018 at 08:13 UTC 108f530385e969feab343b2b8acadeb7bb670009
4 files changed +46 -12
builtin/pack-objects.c
+2 -2
@@ -2716,8 +2716,8 @@ static void show_object(struct object *obj, const char *name, void *data)
2716 depth++;
2717
2718 ent = packlist_find(&to_pack, obj->oid.hash, NULL);
2719 - if (ent && depth > ent->tree_depth)
2720 - ent->tree_depth = depth;
2719 + if (ent && depth > oe_tree_depth(&to_pack, ent))
2720 + oe_set_tree_depth(&to_pack, ent, depth);
2721 }
2722 }
2723
delta-islands.c
+18 -9
@@ -224,17 +224,23 @@ static void mark_remote_island_1(struct remote_island *rl, int is_core_island)
224 island_counter++;
225 }
226
227 -static int cmp_tree_depth(const void *va, const void *vb)
227 +struct tree_islands_todo {
228 + struct object_entry *entry;
229 + unsigned int depth;
230 +};
231 +
232 +static int tree_depth_compare(const void *a, const void *b)
233 {
229 - struct object_entry *a = *(struct object_entry **)va;
230 - struct object_entry *b = *(struct object_entry **)vb;
231 - return a->tree_depth - b->tree_depth;
234 + const struct tree_islands_todo *todo_a = a;
235 + const struct tree_islands_todo *todo_b = b;
236 +
237 + return todo_a->depth - todo_b->depth;
238 }
239
240 void resolve_tree_islands(int progress, struct packing_data *to_pack)
241 {
242 struct progress *progress_state = NULL;
237 - struct object_entry **todo;
243 + struct tree_islands_todo *todo;
244 int nr = 0;
245 int i;
246
@@ -250,16 +256,19 @@ void resolve_tree_islands(int progress, struct packing_data *to_pack)
256 */
257 ALLOC_ARRAY(todo, to_pack->nr_objects);
258 for (i = 0; i < to_pack->nr_objects; i++) {
253 - if (oe_type(&to_pack->objects[i]) == OBJ_TREE)
254 - todo[nr++] = &to_pack->objects[i];
259 + if (oe_type(&to_pack->objects[i]) == OBJ_TREE) {
260 + todo[nr].entry = &to_pack->objects[i];
261 + todo[nr].depth = oe_tree_depth(to_pack, &to_pack->objects[i]);
262 + nr++;
263 + }
264 }
256 - QSORT(todo, nr, cmp_tree_depth);
265 + QSORT(todo, nr, tree_depth_compare);
266
267 if (progress)
268 progress_state = start_progress(_("Propagating island marks"), nr);
269
270 for (i = 0; i < nr; i++) {
262 - struct object_entry *ent = todo[i];
271 + struct object_entry *ent = todo[i].entry;
272 struct island_bitmap *root_marks;
273 struct tree *tree;
274 struct tree_desc desc;
pack-objects.c
+6
@@ -160,6 +160,9 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
160
161 if (!pdata->in_pack_by_idx)
162 REALLOC_ARRAY(pdata->in_pack, pdata->nr_alloc);
163 +
164 + if (pdata->tree_depth)
165 + REALLOC_ARRAY(pdata->tree_depth, pdata->nr_alloc);
166 }
167
168 new_entry = pdata->objects + pdata->nr_objects++;
@@ -175,5 +178,8 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
178 if (pdata->in_pack)
179 pdata->in_pack[pdata->nr_objects - 1] = NULL;
180
181 + if (pdata->tree_depth)
182 + pdata->tree_depth[pdata->nr_objects - 1] = 0;
183 +
184 return new_entry;
185 }
pack-objects.h
+20 -1
@@ -101,7 +101,6 @@ struct object_entry {
101 unsigned no_try_delta:1;
102 unsigned in_pack_type:TYPE_BITS; /* could be delta */
103
104 - unsigned int tree_depth; /* should be repositioned for packing? */
104 unsigned char layer;
105
106 unsigned preferred_base:1; /*
@@ -145,6 +144,9 @@ struct packing_data {
144 struct packed_git **in_pack;
145
146 uintmax_t oe_size_limit;
147 +
148 + /* delta islands */
149 + unsigned int *tree_depth;
150 };
151
152 void prepare_packing_data(struct packing_data *pdata);
@@ -350,4 +352,21 @@ static inline void oe_set_delta_size(struct packing_data *pack,
352 "where delta size is the same as entry size");
353 }
354
355 +static inline unsigned int oe_tree_depth(struct packing_data *pack,
356 + struct object_entry *e)
357 +{
358 + if (!pack->tree_depth)
359 + return 0;
360 + return pack->tree_depth[e - pack->objects];
361 +}
362 +
363 +static inline void oe_set_tree_depth(struct packing_data *pack,
364 + struct object_entry *e,
365 + unsigned int tree_depth)
366 +{
367 + if (!pack->tree_depth)
368 + ALLOC_ARRAY(pack->tree_depth, pack->nr_objects);
369 + pack->tree_depth[e - pack->objects] = tree_depth;
370 +}
371 +
372 #endif