{"thread":{"id":"24655","subject":"[PATCH] pack-object: trim memory usage a tiny bit","startedAt":"2010-08-06T17:00:57Z","lastAt":"2010-08-07T00:21:31Z","messageCount":7,"participants":["Nguyễn Thái Ngọc Duy","Sverre Rabbelier","Nguyen Thai Ngoc Duy","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"147357","messageId":"1281114057-5982-1-git-send-email-pclouds@gmail.com","threadId":"24655","inReplyTo":null,"subject":"[PATCH] pack-object: trim memory usage a tiny bit","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-08-06T17:00:57Z","receivedAt":"2010-08-06T17:00:57Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This shrinks struct object_entry from 88 bytes to 80 bytes on my 32\nbit machine. So that would be 12M less on linux-2.6.git (1.6M objects)\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Don't know if it's really worth a patch..\n\n builtin/pack-objects.c |   18 ++++++++++--------\n 1 files changed, 10 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 0e81673..398c0bb 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -47,14 +47,14 @@ struct object_entry {\n \tunsigned long delta_size;\t/* delta data size (uncompressed) */\n \tunsigned long z_delta_size;\t/* delta data size (compressed) */\n \tunsigned int hash;\t/* name hint hash */\n-\tenum object_type type;\n-\tenum object_type in_pack_type;\t/* could be delta */\n+\tenum object_type type:5;\n+\tenum object_type in_pack_type:5;\t/* could be delta */\n \tunsigned char in_pack_header_size;\n-\tunsigned char preferred_base; /* we do not pack this, but is available\n-\t\t\t\t       * to be used as the base object to delta\n-\t\t\t\t       * objects against.\n-\t\t\t\t       */\n-\tunsigned char no_try_delta;\n+\tunsigned char preferred_base:1; /* we do not pack this, but is available\n+\t\t\t\t\t * to be used as the base object to delta\n+\t\t\t\t\t * objects against.\n+\t\t\t\t\t */\n+\tunsigned char no_try_delta:1;\n };\n \n /*\n@@ -1001,6 +1001,7 @@ static void check_object(struct object_entry *entry)\n \t\tunsigned int avail;\n \t\toff_t ofs;\n \t\tunsigned char *buf, c;\n+\t\tenum object_type in_pack_type;\n \n \t\tbuf = use_pack(p, &w_curs, entry->in_pack_offset, &avail);\n \n@@ -1009,8 +1010,9 @@ static void check_object(struct object_entry *entry)\n \t\t * since non-delta representations could still be reused.\n \t\t */\n \t\tused = unpack_object_header_buffer(buf, avail,\n-\t\t\t\t\t\t   &entry->in_pack_type,\n+\t\t\t\t\t\t   &in_pack_type,\n \t\t\t\t\t\t   &entry->size);\n+\t\tentry->in_pack_type = in_pack_type;\n \t\tif (used == 0)\n \t\t\tgoto give_up;\n \n-- \n1.7.1.rc1.69.g24c2f7\n"},{"id":"147358","messageId":"AANLkTikphara-0NXaBZ-MAygytGYDuN6ANcMWE+Ni3mW@mail.gmail.com","threadId":"24655","inReplyTo":"1281114057-5982-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] pack-object: trim memory usage a tiny bit","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-08-06T23:58:07Z","receivedAt":"2010-08-06T23:58:07Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\n2010/8/6 Nguyễn Thái Ngọc Duy <pclouds@gmail.com>:\n> This shrinks struct object_entry from 88 bytes to 80 bytes on my 32\n> bit machine. So that would be 12M less on linux-2.6.git (1.6M objects)\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  Don't know if it's really worth a patch..\n\nEither way, some explanation would be nice.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"147359","messageId":"AANLkTikL8MtqFr1T=3TKA7GLKSEbyvf+6SLTT2BYehto@mail.gmail.com","threadId":"24655","inReplyTo":"AANLkTikphara-0NXaBZ-MAygytGYDuN6ANcMWE+Ni3mW@mail.gmail.com","subject":"Re: [PATCH] pack-object: trim memory usage a tiny bit","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-08-07T00:03:40Z","receivedAt":"2010-08-07T00:03:40Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2010/8/7 Sverre Rabbelier <srabbelier@gmail.com>:\n> Heya,\n>\n> 2010/8/6 Nguyễn Thái Ngọc Duy <pclouds@gmail.com>:\n>> This shrinks struct object_entry from 88 bytes to 80 bytes on my 32\n>> bit machine. So that would be 12M less on linux-2.6.git (1.6M objects)\n>>\n>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>> ---\n>>  Don't know if it's really worth a patch..\n>\n> Either way, some explanation would be nice.\n\nstruct object_entry is allocated for every object to be packed. So if\nyou do a clone on linux-2.6, you would need 1.6M of those structs, 88\nbytes each. I cut 8 bytes from each of them.\n-- \nDuy\n"},{"id":"147360","messageId":"AANLkTingdhx5osnbiLVMyWaauCf1TRiMzcSC76gQRp9B@mail.gmail.com","threadId":"24655","inReplyTo":"AANLkTikL8MtqFr1T=3TKA7GLKSEbyvf+6SLTT2BYehto@mail.gmail.com","subject":"Re: [PATCH] pack-object: trim memory usage a tiny bit","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-08-07T00:04:26Z","receivedAt":"2010-08-07T00:04:26Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Fri, Aug 6, 2010 at 19:03, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n> struct object_entry is allocated for every object to be packed. So if\n> you do a clone on linux-2.6, you would need 1.6M of those structs, 88\n> bytes each. I cut 8 bytes from each of them.\n\nSure, that was clear enough. But _how_? What needs to be done to\nretain this? Are there any downsides?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"147361","messageId":"AANLkTimEFjRuuO+GnAV7PGe0oPi-Qh37iLS6o3Q8Undw@mail.gmail.com","threadId":"24655","inReplyTo":"AANLkTingdhx5osnbiLVMyWaauCf1TRiMzcSC76gQRp9B@mail.gmail.com","subject":"Re: [PATCH] pack-object: trim memory usage a tiny bit","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-08-07T00:16:43Z","receivedAt":"2010-08-07T00:16:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Aug 7, 2010 at 10:04 AM, Sverre Rabbelier <srabbelier@gmail.com> wrote:\n> Heya,\n>\n> On Fri, Aug 6, 2010 at 19:03, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n>> struct object_entry is allocated for every object to be packed. So if\n>> you do a clone on linux-2.6, you would need 1.6M of those structs, 88\n>> bytes each. I cut 8 bytes from each of them.\n>\n> Sure, that was clear enough. But _how_? What needs to be done to\n> retain this? Are there any downsides?\n\nAh, by packing it tighter using bitfields. There are two fields that\nact as boolean, but they use at least one byte each. And enum\nobject_type, I recall, uses 4 bytes (int), while it only needs 5 bits\n(4 bits is enough if OBJ_BAD is not counted). No downsides I know of.\n-- \nDuy\n"},{"id":"147362","messageId":"20100807001829.GQ25268@spearce.org","threadId":"24655","inReplyTo":"AANLkTimEFjRuuO+GnAV7PGe0oPi-Qh37iLS6o3Q8Undw@mail.gmail.com","subject":"Re: [PATCH] pack-object: trim memory usage a tiny bit","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2010-08-07T00:18:29Z","receivedAt":"2010-08-07T00:18:29Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n> \n> Ah, by packing it tighter using bitfields. There are two fields that\n> act as boolean, but they use at least one byte each. And enum\n> object_type, I recall, uses 4 bytes (int), while it only needs 5 bits\n> (4 bits is enough if OBJ_BAD is not counted). No downsides I know of.\n\nActually, object type is 3 bits in the pack file.  So unless its\nusing some additional magical values, 4 bits is sufficient to get\nyou 3 bits and the -1 bad value.\n\n-- \nShawn.\n"},{"id":"147363","messageId":"AANLkTinFQan-kdaW-wQ5Ca6WATgpDQzhA68w7WODeEFE@mail.gmail.com","threadId":"24655","inReplyTo":"20100807001829.GQ25268@spearce.org","subject":"Re: [PATCH] pack-object: trim memory usage a tiny bit","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-08-07T00:21:31Z","receivedAt":"2010-08-07T00:21:31Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Aug 7, 2010 at 10:18 AM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n>>\n>> Ah, by packing it tighter using bitfields. There are two fields that\n>> act as boolean, but they use at least one byte each. And enum\n>> object_type, I recall, uses 4 bytes (int), while it only needs 5 bits\n>> (4 bits is enough if OBJ_BAD is not counted). No downsides I know of.\n>\n> Actually, object type is 3 bits in the pack file.  So unless its\n> using some additional magical values, 4 bits is sufficient to get\n> you 3 bits and the -1 bad value.\n\nRight. Obviously I miscounted.\n-- \nDuy\n"}]}