Skip to content

Commit 0cb3c14

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898eba5 commit 0cb3c14

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

Documentation/config.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,8 @@ pack.deltaCacheLimit::
24592459
The maximum size of a delta, that is cached in
24602460
linkgit:git-pack-objects[1]. This cache is used to speed up the
24612461
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.
24632464

24642465
pack.threads::
24652466
Specifies the number of threads to spawn when searching for best

builtin/pack-objects.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,12 +2099,19 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
20992099
* between writes at that moment.
21002100
*/
21012101
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+
}
21082115
}
21092116

21102117
/* 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)
30873094
depth, (1 << OE_DEPTH_BITS) - 1);
30883095
depth = (1 << OE_DEPTH_BITS) - 1;
30893096
}
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+
}
30903102

30913103
argv_array_push(&rp, "pack-objects");
30923104
if (thin) {

pack-objects.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define OE_DFS_STATE_BITS 2
77
#define OE_DEPTH_BITS 12
88
#define OE_IN_PACK_BITS 10
9+
#define OE_Z_DELTA_BITS 20
910

1011
/*
1112
* State flags for depth-first search used for analyzing delta cycles.
@@ -77,7 +78,7 @@ struct object_entry {
7778
*/
7879
void *delta_data; /* cached delta (uncompressed) */
7980
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;
8182
unsigned type_:TYPE_BITS;
8283
unsigned in_pack_type:TYPE_BITS; /* could be delta */
8384
unsigned type_valid:1;

0 commit comments

Comments
 (0)