pack-redundant: delay creation of unique_objects
Instead of initializing unique_objects in `add_pack()`, copy from all_objects in `cmp_two_packs()`, when unwanted objects are removed from all_objects. This will save memory (no allocate memory for alt-odb packs), and run `llist_sorted_difference_inplace()` only once when removing ignored objects and removing objects in alt-odb in `scan_alt_odb_packs()`. Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jiang Xin committed
Feb 2, 2019 at 21:30 UTC
301117764041101ae228e8e33c12c0b232b06408
1 file changed
+10
-5
builtin/pack-redundant.c
+10
-5
@@ -254,6 +254,11 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
254
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
255
const unsigned int hashsz = the_hash_algo->rawsz;
256
257
+ if (!p1->unique_objects)
258
+ p1->unique_objects = llist_copy(p1->all_objects);
259
+ if (!p2->unique_objects)
260
+ p2->unique_objects = llist_copy(p2->all_objects);
261
+
262
p1_base = p1->pack->index_data;
263
p2_base = p2->pack->index_data;
264
p1_base += 256 * 4 + ((p1->pack->index_version < 2) ? 4 : 8);
@@ -536,7 +541,7 @@ static void scan_alt_odb_packs(void)
541
while (alt) {
542
local = local_packs;
543
while (local) {
539
- llist_sorted_difference_inplace(local->unique_objects,
544
+ llist_sorted_difference_inplace(local->all_objects,
545
alt->all_objects);
546
local = local->next;
547
}
@@ -567,8 +572,7 @@ static struct pack_list * add_pack(struct packed_git *p)
572
llist_insert_back(l.all_objects, (const struct object_id *)(base + off));
573
off += step;
574
}
570
- /* this list will be pruned in cmp_two_packs later */
571
- l.unique_objects = llist_copy(l.all_objects);
575
+ l.unique_objects = NULL;
576
if (p->pack_local)
577
return pack_list_insert(&local_packs, &l);
578
else
@@ -646,7 +650,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
650
651
load_all_objects();
652
649
- cmp_local_packs();
653
if (alt_odb)
654
scan_alt_odb_packs();
655
@@ -663,10 +666,12 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
666
llist_sorted_difference_inplace(all_objects, ignore);
667
pl = local_packs;
668
while (pl) {
666
- llist_sorted_difference_inplace(pl->unique_objects, ignore);
669
+ llist_sorted_difference_inplace(pl->all_objects, ignore);
670
pl = pl->next;
671
}
672
673
+ cmp_local_packs();
674
+
675
minimize(&min);
676
677
if (verbose) {