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 <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>
maint
Christian Couder 2018-08-16 08:13:13 +02:00 committed by Junio C Hamano
parent 108f530385
commit fe0ac2fb7f
4 changed files with 28 additions and 6 deletions

View File

@ -611,7 +611,7 @@ static inline void add_to_write_order(struct object_entry **wo,
unsigned int *endp, unsigned int *endp,
struct object_entry *e) struct object_entry *e)
{ {
if (e->filled || e->layer != write_layer) if (e->filled || oe_layer(&to_pack, e) != write_layer)
return; return;
wo[(*endp)++] = e; wo[(*endp)++] = e;
e->filled = 1; e->filled = 1;
@ -714,7 +714,7 @@ static void compute_layer_order(struct object_entry **wo, unsigned int *wo_end)
* Finally all the rest in really tight order * Finally all the rest in really tight order
*/ */
for (i = last_untagged; i < to_pack.nr_objects; i++) { for (i = last_untagged; i < to_pack.nr_objects; i++) {
if (!objects[i].filled && objects[i].layer == write_layer) if (!objects[i].filled && oe_layer(&to_pack, &objects[i]) == write_layer)
add_family_to_write_order(wo, wo_end, &objects[i]); add_family_to_write_order(wo, wo_end, &objects[i]);
} }
} }

View File

@ -488,13 +488,13 @@ int compute_pack_layers(struct packing_data *to_pack)
struct object_entry *entry = &to_pack->objects[i]; struct object_entry *entry = &to_pack->objects[i];
khiter_t pos = kh_get_sha1(island_marks, entry->idx.oid.hash); khiter_t pos = kh_get_sha1(island_marks, entry->idx.oid.hash);


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


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


if (island_bitmap_get(bitmap, island_counter_core)) if (island_bitmap_get(bitmap, island_counter_core))
entry->layer = 0; oe_set_layer(to_pack, entry, 0);
} }
} }



View File

@ -163,6 +163,9 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,


if (pdata->tree_depth) if (pdata->tree_depth)
REALLOC_ARRAY(pdata->tree_depth, pdata->nr_alloc); REALLOC_ARRAY(pdata->tree_depth, pdata->nr_alloc);

if (pdata->layer)
REALLOC_ARRAY(pdata->layer, pdata->nr_alloc);
} }


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


if (pdata->layer)
pdata->layer[pdata->nr_objects - 1] = 0;

return new_entry; return new_entry;
} }

View File

@ -101,8 +101,6 @@ struct object_entry {
unsigned no_try_delta:1; unsigned no_try_delta:1;
unsigned in_pack_type:TYPE_BITS; /* could be delta */ unsigned in_pack_type:TYPE_BITS; /* could be delta */


unsigned char layer;

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


/* delta islands */ /* delta islands */
unsigned int *tree_depth; unsigned int *tree_depth;
unsigned char *layer;
}; };


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


static inline unsigned char oe_layer(struct packing_data *pack,
struct object_entry *e)
{
if (!pack->layer)
return 0;
return pack->layer[e - pack->objects];
}

static inline void oe_set_layer(struct packing_data *pack,
struct object_entry *e,
unsigned char layer)
{
if (!pack->layer)
ALLOC_ARRAY(pack->layer, pack->nr_objects);
pack->layer[e - pack->objects] = layer;
}

#endif #endif