pack-objects: shrink z_delta_size field in struct object_entry
We only cache deltas when it's smaller than a certain limit. This limit defaults to 1000 but save its compressed length in a 64-bit field. Shrink that field down to 20 bits, so you can only cache 1MB deltas. Larger deltas must be recomputed at when the pack is written down. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Apr 14, 2018 at 17:35 UTC
0cb3c1427a1e9cee638e0c1629933c907493d7e3
3 files changed
+22
-8
Documentation/config.txt
+2
-1
@@ -2459,7 +2459,8 @@ pack.deltaCacheLimit::
2459
The maximum size of a delta, that is cached in
2460
linkgit:git-pack-objects[1]. This cache is used to speed up the
2461
writing object phase by not having to recompute the final delta
2462
- result once the best match for all objects is found. Defaults to 1000.
2462
+ result once the best match for all objects is found.
2463
+ Defaults to 1000. Maximum value is 65535.
2464
2465
pack.threads::
2466
Specifies the number of threads to spawn when searching for best
builtin/pack-objects.c
+18
-6
@@ -2099,12 +2099,19 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
2099
* between writes at that moment.
2100
*/
2101
if (entry->delta_data && !pack_to_stdout) {
2102
- entry->z_delta_size = do_compress(&entry->delta_data,
2103
- entry->delta_size);
2104
- cache_lock();
2105
- delta_cache_size -= entry->delta_size;
2106
- delta_cache_size += entry->z_delta_size;
2107
- cache_unlock();
2102
+ unsigned long size;
2103
+
2104
+ size = do_compress(&entry->delta_data, entry->delta_size);
2105
+ if (size < (1U << OE_Z_DELTA_BITS)) {
2106
+ entry->z_delta_size = size;
2107
+ cache_lock();
2108
+ delta_cache_size -= entry->delta_size;
2109
+ delta_cache_size += entry->z_delta_size;
2110
+ cache_unlock();
2111
+ } else {
2112
+ FREE_AND_NULL(entry->delta_data);
2113
+ entry->z_delta_size = 0;
2114
+ }
2115
}
2116
2117
/* if we made n a delta, and if n is already at max
@@ -3087,6 +3094,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
3094
depth, (1 << OE_DEPTH_BITS) - 1);
3095
depth = (1 << OE_DEPTH_BITS) - 1;
3096
}
3097
+ if (cache_max_small_delta_size >= (1U << OE_Z_DELTA_BITS)) {
3098
+ warning(_("pack.deltaCacheLimit is too high, forcing %d"),
3099
+ (1U << OE_Z_DELTA_BITS) - 1);
3100
+ cache_max_small_delta_size = (1U << OE_Z_DELTA_BITS) - 1;
3101
+ }
3102
3103
argv_array_push(&rp, "pack-objects");
3104
if (thin) {
pack-objects.h
+2
-1
@@ -6,6 +6,7 @@
6
#define OE_DFS_STATE_BITS 2
7
#define OE_DEPTH_BITS 12
8
#define OE_IN_PACK_BITS 10
9
+#define OE_Z_DELTA_BITS 20
10
11
/*
12
* State flags for depth-first search used for analyzing delta cycles.
@@ -77,7 +78,7 @@ struct object_entry {
78
*/
79
void *delta_data; /* cached delta (uncompressed) */
80
unsigned long delta_size; /* delta data size (uncompressed) */
80
- unsigned long z_delta_size; /* delta data size (compressed) */
81
+ unsigned z_delta_size:OE_Z_DELTA_BITS;
82
unsigned type_:TYPE_BITS;
83
unsigned in_pack_type:TYPE_BITS; /* could be delta */
84
unsigned type_valid:1;