pack-objects: reorder members to shrink struct object_entry

Previous patches leave lots of holes and padding in this struct. This patch reorders the members and shrinks the struct down to 80 bytes (from 136 bytes on 64-bit systems, before any field shrinking is done) with 16 bits to spare (and a couple more in in_pack_header_size when we really run out of bits). This is the last in a series of memory reduction patches (see "pack-objects: a bit of document about struct object_entry" for the first one). Overall they've reduced repack memory size on linux-2.6.git from 3.747G to 3.424G, or by around 320M, a decrease of 8.5%. The runtime of repack has stayed the same throughout this series. Ævar's testing on a big monorepo he has access to (bigger than linux-2.6.git) has shown a 7.9% reduction, so the overall expected improvement should be somewhere around 8%. See 87po42cwql.fsf@evledraar.gmail.com on-list (https://public-inbox.org/git/87po42cwql.fsf@evledraar.gmail.com/) for more detailed numbers and a test script used to produce the numbers cited above. 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 3b13a5f263872c4643f7f0eb6eccb7a8196b2760
1 file changed +21 -7
pack-objects.h
+21 -7
@@ -28,6 +28,10 @@ enum dfs_state {
28 };
29
30 /*
31 + * The size of struct nearly determines pack-objects's memory
32 + * consumption. This struct is packed tight for that reason. When you
33 + * add or reorder something in this struct, think a bit about this.
34 + *
35 * basic object info
36 * -----------------
37 * idx.oid is filled up before delta searching starts. idx.crc32 is
@@ -76,34 +80,44 @@ enum dfs_state {
80 */
81 struct object_entry {
82 struct pack_idx_entry idx;
83 + void *delta_data; /* cached delta (uncompressed) */
84 + off_t in_pack_offset;
85 + uint32_t hash; /* name hint hash */
86 unsigned size_:OE_SIZE_BITS;
87 unsigned size_valid:1;
81 - unsigned in_pack_idx:OE_IN_PACK_BITS; /* already in pack */
82 - off_t in_pack_offset;
88 uint32_t delta_idx; /* delta base object */
89 uint32_t delta_child_idx; /* deltified objects who bases me */
90 uint32_t delta_sibling_idx; /* other deltified objects who
91 * uses the same base as me
92 */
88 - void *delta_data; /* cached delta (uncompressed) */
93 unsigned delta_size_:OE_DELTA_SIZE_BITS; /* delta data size (uncompressed) */
94 unsigned delta_size_valid:1;
95 + unsigned in_pack_idx:OE_IN_PACK_BITS; /* already in pack */
96 unsigned z_delta_size:OE_Z_DELTA_BITS;
97 + unsigned type_valid:1;
98 unsigned type_:TYPE_BITS;
99 + unsigned no_try_delta:1;
100 unsigned in_pack_type:TYPE_BITS; /* could be delta */
94 - unsigned type_valid:1;
95 - uint32_t hash; /* name hint hash */
96 - unsigned char in_pack_header_size;
101 unsigned preferred_base:1; /*
102 * we do not pack this, but is available
103 * to be used as the base object to delta
104 * objects against.
105 */
102 - unsigned no_try_delta:1;
106 unsigned tagged:1; /* near the very tip of refs */
107 unsigned filled:1; /* assigned write-order */
108 unsigned dfs_state:OE_DFS_STATE_BITS;
109 + unsigned char in_pack_header_size;
110 unsigned depth:OE_DEPTH_BITS;
111 +
112 + /*
113 + * pahole results on 64-bit linux (gcc and clang)
114 + *
115 + * size: 80, bit_padding: 20 bits, holes: 8 bits
116 + *
117 + * and on 32-bit (gcc)
118 + *
119 + * size: 76, bit_padding: 20 bits, holes: 8 bits
120 + */
121 };
122
123 struct packing_data {