Skip to content

Commit 3b13a5f

Browse files
pcloudsgitster
authored andcommitted
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 [email protected] on-list (https://public-inbox.org/git/[email protected]/) 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0aca34e commit 3b13a5f

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

pack-objects.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ enum dfs_state {
2828
};
2929

3030
/*
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+
*
3135
* basic object info
3236
* -----------------
3337
* idx.oid is filled up before delta searching starts. idx.crc32 is
@@ -76,34 +80,44 @@ enum dfs_state {
7680
*/
7781
struct object_entry {
7882
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 */
7986
unsigned size_:OE_SIZE_BITS;
8087
unsigned size_valid:1;
81-
unsigned in_pack_idx:OE_IN_PACK_BITS; /* already in pack */
82-
off_t in_pack_offset;
8388
uint32_t delta_idx; /* delta base object */
8489
uint32_t delta_child_idx; /* deltified objects who bases me */
8590
uint32_t delta_sibling_idx; /* other deltified objects who
8691
* uses the same base as me
8792
*/
88-
void *delta_data; /* cached delta (uncompressed) */
8993
unsigned delta_size_:OE_DELTA_SIZE_BITS; /* delta data size (uncompressed) */
9094
unsigned delta_size_valid:1;
95+
unsigned in_pack_idx:OE_IN_PACK_BITS; /* already in pack */
9196
unsigned z_delta_size:OE_Z_DELTA_BITS;
97+
unsigned type_valid:1;
9298
unsigned type_:TYPE_BITS;
99+
unsigned no_try_delta:1;
93100
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;
97101
unsigned preferred_base:1; /*
98102
* we do not pack this, but is available
99103
* to be used as the base object to delta
100104
* objects against.
101105
*/
102-
unsigned no_try_delta:1;
103106
unsigned tagged:1; /* near the very tip of refs */
104107
unsigned filled:1; /* assigned write-order */
105108
unsigned dfs_state:OE_DFS_STATE_BITS;
109+
unsigned char in_pack_header_size;
106110
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+
*/
107121
};
108122

109123
struct packing_data {

0 commit comments

Comments
 (0)