@matheusbsbs / matheus-bagliano / commits / 776398709d
Fork 0

Keep last used delta base in the delta window

This is based on Martin Koegler's idea to keep the object that was successfully used as the base of the delta when it is about to fall off the edge of the window. Instead of doing so only for the objects at the edge of the window, this makes the window a lru eviction mechanism. If an entry is used as a base, it is moved to the last of the queue to be evicted. This is a quick-and-dirty implementation, as it keeps the original implementation of the data structure used for the window. This originally was done as an array, not as an array of pointers, because it was meant to be used as a cyclic FIFO buffer and a plain array avoids an extra pointer indirection, while its FIFOness eant that we are not "moving" the entries like this patch does. The runtime from three versions were comparable. It seems to make the resulting chain even shorter, which can only be good. (stock "master") 15782196 bytes chain length = 1: 2972 objects chain length = 2: 2651 objects chain length = 3: 2369 objects chain length = 4: 2121 objects chain length = 5: 1877 objects ... chain length = 46: 490 objects chain length = 47: 515 objects chain length = 48: 527 objects chain length = 49: 570 objects chain length = 50: 408 objects (with your patch) 15745736 bytes (0.23% smaller) chain length = 1: 3137 objects chain length = 2: 2688 objects chain length = 3: 2322 objects chain length = 4: 2146 objects chain length = 5: 1824 objects ... chain length = 46: 503 objects chain length = 47: 509 objects chain length = 48: 536 objects chain length = 49: 588 objects chain length = 50: 357 objects (with this patch) 15612086 bytes (1.08% smaller) chain length = 1: 4831 objects chain length = 2: 3811 objects chain length = 3: 2964 objects chain length = 4: 2352 objects chain length = 5: 1944 objects ... chain length = 46: 327 objects chain length = 47: 353 objects chain length = 48: 304 objects chain length = 49: 298 objects chain length = 50: 135 objects [jc: this is with code simplification follow-up from Nico] Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 1, 2007 at 23:53 UTC 776398709dee4050fc194fec45c5818ba9b01afe
1 file changed +23 -2
builtin-pack-objects.c
+23 -2
@@ -1460,7 +1460,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1460 do {
1461 struct object_entry *entry = list[--i];
1462 struct unpacked *n = array + idx;
1463 - int j;
1463 + int j, best_base = -1;
1464
1465 if (!entry->preferred_base)
1466 processed++;
@@ -1505,6 +1505,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1505
1506 j = window;
1507 while (--j > 0) {
1508 + int ret;
1509 uint32_t other_idx = idx + j;
1510 struct unpacked *m;
1511 if (other_idx >= window)
@@ -1512,8 +1513,11 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1513 m = array + other_idx;
1514 if (!m->entry)
1515 break;
1515 - if (try_delta(n, m, max_depth) < 0)
1516 + ret = try_delta(n, m, max_depth);
1517 + if (ret < 0)
1518 break;
1519 + else if (ret > 0)
1520 + best_base = other_idx;
1521 }
1522
1523 /* if we made n a delta, and if n is already at max
@@ -1523,6 +1527,23 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1527 if (entry->delta && depth <= n->depth)
1528 continue;
1529
1530 + /*
1531 + * Move the best delta base up in the window, after the
1532 + * currently deltified object, to keep it longer. It will
1533 + * be the first base object to be attempted next.
1534 + */
1535 + if (entry->delta) {
1536 + struct unpacked swap = array[best_base];
1537 + int dist = (window + idx - best_base) % window;
1538 + int dst = best_base;
1539 + while (dist--) {
1540 + int src = (dst + 1) % window;
1541 + array[dst] = array[src];
1542 + dst = src;
1543 + }
1544 + array[dst] = swap;
1545 + }
1546 +
1547 next:
1548 idx++;
1549 if (count + 1 < window)