Skip to content

Commit fe0ac2f

Browse files
chriscoolgitster
authored andcommitted
pack-objects: move 'layer' into 'struct packing_data'
This reduces the size of 'struct object_entry' from 88 bytes to 80 and therefore makes packing objects more efficient. For example on a Linux repo with 12M objects, `git pack-objects --all` needs extra 96MB memory even if the layer feature is not used. Helped-by: Jeff King <[email protected]> Helped-by: Duy Nguyen <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 108f530 commit fe0ac2f

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static inline void add_to_write_order(struct object_entry **wo,
611611
unsigned int *endp,
612612
struct object_entry *e)
613613
{
614-
if (e->filled || e->layer != write_layer)
614+
if (e->filled || oe_layer(&to_pack, e) != write_layer)
615615
return;
616616
wo[(*endp)++] = e;
617617
e->filled = 1;
@@ -714,7 +714,7 @@ static void compute_layer_order(struct object_entry **wo, unsigned int *wo_end)
714714
* Finally all the rest in really tight order
715715
*/
716716
for (i = last_untagged; i < to_pack.nr_objects; i++) {
717-
if (!objects[i].filled && objects[i].layer == write_layer)
717+
if (!objects[i].filled && oe_layer(&to_pack, &objects[i]) == write_layer)
718718
add_family_to_write_order(wo, wo_end, &objects[i]);
719719
}
720720
}

delta-islands.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,13 @@ int compute_pack_layers(struct packing_data *to_pack)
488488
struct object_entry *entry = &to_pack->objects[i];
489489
khiter_t pos = kh_get_sha1(island_marks, entry->idx.oid.hash);
490490

491-
entry->layer = 1;
491+
oe_set_layer(to_pack, entry, 1);
492492

493493
if (pos < kh_end(island_marks)) {
494494
struct island_bitmap *bitmap = kh_value(island_marks, pos);
495495

496496
if (island_bitmap_get(bitmap, island_counter_core))
497-
entry->layer = 0;
497+
oe_set_layer(to_pack, entry, 0);
498498
}
499499
}
500500

pack-objects.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
163163

164164
if (pdata->tree_depth)
165165
REALLOC_ARRAY(pdata->tree_depth, pdata->nr_alloc);
166+
167+
if (pdata->layer)
168+
REALLOC_ARRAY(pdata->layer, pdata->nr_alloc);
166169
}
167170

168171
new_entry = pdata->objects + pdata->nr_objects++;
@@ -181,5 +184,8 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
181184
if (pdata->tree_depth)
182185
pdata->tree_depth[pdata->nr_objects - 1] = 0;
183186

187+
if (pdata->layer)
188+
pdata->layer[pdata->nr_objects - 1] = 0;
189+
184190
return new_entry;
185191
}

pack-objects.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ struct object_entry {
101101
unsigned no_try_delta:1;
102102
unsigned in_pack_type:TYPE_BITS; /* could be delta */
103103

104-
unsigned char layer;
105-
106104
unsigned preferred_base:1; /*
107105
* we do not pack this, but is available
108106
* to be used as the base object to delta
@@ -147,6 +145,7 @@ struct packing_data {
147145

148146
/* delta islands */
149147
unsigned int *tree_depth;
148+
unsigned char *layer;
150149
};
151150

152151
void prepare_packing_data(struct packing_data *pdata);
@@ -369,4 +368,21 @@ static inline void oe_set_tree_depth(struct packing_data *pack,
369368
pack->tree_depth[e - pack->objects] = tree_depth;
370369
}
371370

371+
static inline unsigned char oe_layer(struct packing_data *pack,
372+
struct object_entry *e)
373+
{
374+
if (!pack->layer)
375+
return 0;
376+
return pack->layer[e - pack->objects];
377+
}
378+
379+
static inline void oe_set_layer(struct packing_data *pack,
380+
struct object_entry *e,
381+
unsigned char layer)
382+
{
383+
if (!pack->layer)
384+
ALLOC_ARRAY(pack->layer, pack->nr_objects);
385+
pack->layer[e - pack->objects] = layer;
386+
}
387+
372388
#endif

0 commit comments

Comments
 (0)