@matheusbsbs / matheus-bagliano / commits / c83f032e09
Fork 0

apply delta depth bias to already deltified objects

We already apply a bias on the initial delta attempt with max_size being a function of the base object depth. This has the effect of favoring shallower deltas even if deeper deltas could be smaller, and therefore creating a wider delta tree (see commits 4e8da195 and c3b06a69). This principle should also be applied to all delta attempts for the same object and not only the first attempt. With this the criteria for the best delta is not only its size but also its depth, so that a shallower delta might be selected even if it is larger than a deeper one. Even if some deltas get larger, they allow for wider delta trees making the depth limit less quickly reached and therefore better deltas can be subsequently found, keeping the resulting pack size even smaller. Runtime access to the pack should also benefit from shallower deltas. Testing on different repositories showed slighter faster repacks, smaller resulting packs, and a much nicer curve for delta depth distribution with no more peak at the maximum depth level. Improvements are even more significant with smaller depth limits. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Jul 12, 2007 at 14:33 UTC c83f032e09e49e5bc60686663f7c78d36f72cef4
1 file changed +10 -4
builtin-pack-objects.c
+10 -4
@@ -1303,6 +1303,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1303 struct object_entry *trg_entry = trg->entry;
1304 struct object_entry *src_entry = src->entry;
1305 unsigned long trg_size, src_size, delta_size, sizediff, max_size, sz;
1306 + unsigned ref_depth;
1307 enum object_type type;
1308 void *delta_buf;
1309
@@ -1332,12 +1333,17 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1333
1334 /* Now some size filtering heuristics. */
1335 trg_size = trg_entry->size;
1335 - max_size = trg_size/2 - 20;
1336 - max_size = max_size * (max_depth - src_entry->depth) / max_depth;
1336 + if (!trg_entry->delta) {
1337 + max_size = trg_size/2 - 20;
1338 + ref_depth = 1;
1339 + } else {
1340 + max_size = trg_entry->delta_size;
1341 + ref_depth = trg_entry->depth;
1342 + }
1343 + max_size = max_size * (max_depth - src_entry->depth) /
1344 + (max_depth - ref_depth + 1);
1345 if (max_size == 0)
1346 return 0;
1339 - if (trg_entry->delta && trg_entry->delta_size <= max_size)
1340 - max_size = trg_entry->delta_size;
1347 src_size = src_entry->size;
1348 sizediff = src_size < trg_size ? trg_size - src_size : 0;
1349 if (sizediff >= max_size)