Make git-pack-redundant non-horribly slow on large sets of packs
Change the smallest-set detection algortithm so that when we have found a good set, we don't check any larger sets. Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
Lukas Sandström committed
Nov 17, 2005 at 14:11 UTC
751a71e2b5f3667ab7ffffccad3e2b58726eb1c9
1 file changed
+48
-12
pack-redundant.c
+48
-12
@@ -33,6 +33,7 @@ struct pack_list {
33
struct pll {
34
struct pll *next;
35
struct pack_list *pl;
36
+ size_t pl_size;
37
};
38
39
inline void llist_free(struct llist *list)
@@ -249,18 +250,45 @@ void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
250
}
251
}
252
253
+void pll_insert(struct pll **pll, struct pll **hint_table)
254
+{
255
+ struct pll *prev;
256
+ int i = (*pll)->pl_size - 1;
257
+
258
+ if (hint_table[i] == NULL) {
259
+ hint_table[i--] = *pll;
260
+ for (; i >= 0; --i) {
261
+ if (hint_table[i] != NULL)
262
+ break;
263
+ }
264
+ if (hint_table[i] == NULL) /* no elements in list */
265
+ die("Why did this happen?");
266
+ }
267
+
268
+ prev = hint_table[i];
269
+ while (prev->next && prev->next->pl_size < (*pll)->pl_size)
270
+ prev = prev->next;
271
+
272
+ (*pll)->next = prev->next;
273
+ prev->next = *pll;
274
+}
275
+
276
/* all the permutations have to be free()d at the same time,
277
* since they refer to each other
278
*/
279
struct pll * get_all_permutations(struct pack_list *list)
280
{
281
struct pll *subset, *pll, *new_pll = NULL; /*silence warning*/
258
-
282
+ static struct pll **hint = NULL;
283
+ if (hint == NULL)
284
+ hint = xcalloc(pack_list_size(list), sizeof(struct pll *));
285
+
286
if (list == NULL)
287
return NULL;
288
289
if (list->next == NULL) {
290
new_pll = xmalloc(sizeof(struct pll));
291
+ hint[0] = new_pll;
292
new_pll->next = NULL;
293
new_pll->pl = list;
294
return new_pll;
@@ -268,24 +296,30 @@ struct pll * get_all_permutations(struct pack_list *list)
296
297
pll = subset = get_all_permutations(list->next);
298
while (pll) {
299
+ if (pll->pl->pack == list->pack) {
300
+ pll = pll->next;
301
+ continue;
302
+ }
303
new_pll = xmalloc(sizeof(struct pll));
272
- new_pll->next = pll->next;
273
- pll->next = new_pll;
304
305
new_pll->pl = xmalloc(sizeof(struct pack_list));
306
memcpy(new_pll->pl, list, sizeof(struct pack_list));
307
new_pll->pl->next = pll->pl;
308
+ new_pll->pl_size = pll->pl_size + 1;
309
+
310
+ pll_insert(&new_pll, hint);
311
279
- pll = new_pll->next;
312
+ pll = pll->next;
313
}
281
- /* add ourself to the end */
282
- new_pll->next = xmalloc(sizeof(struct pll));
283
- new_pll->next->pl = xmalloc(sizeof(struct pack_list));
284
- new_pll->next->next = NULL;
285
- memcpy(new_pll->next->pl, list, sizeof(struct pack_list));
286
- new_pll->next->pl->next = NULL;
287
-
288
- return subset;
314
+ /* add ourself */
315
+ new_pll = xmalloc(sizeof(struct pll));
316
+ new_pll->pl = xmalloc(sizeof(struct pack_list));
317
+ memcpy(new_pll->pl, list, sizeof(struct pack_list));
318
+ new_pll->pl->next = NULL;
319
+ new_pll->pl_size = 1;
320
+ pll_insert(&new_pll, hint);
321
+
322
+ return hint[0];
323
}
324
325
int is_superset(struct pack_list *pl, struct llist *list)
@@ -401,6 +435,8 @@ void minimize(struct pack_list **min)
435
/* find the permutations which contain all missing objects */
436
perm_all = perm = get_all_permutations(non_unique);
437
while (perm) {
438
+ if (perm_ok && perm->pl_size > perm_ok->pl_size)
439
+ break; /* ignore all larger permutations */
440
if (is_superset(perm->pl, missing)) {
441
new_perm = xmalloc(sizeof(struct pll));
442
new_perm->pl = perm->pl;