From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id AC0111F8C7 for ; Wed, 7 Jul 2021 23:10:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbhGGXNa (ORCPT ); Wed, 7 Jul 2021 19:13:30 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:54580 "EHLO dcvr.yhbt.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbhGGXNT (ORCPT ); Wed, 7 Jul 2021 19:13:19 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A3FDE1F8C9; Wed, 7 Jul 2021 23:10:20 +0000 (UTC) From: Eric Wong To: Junio C Hamano , git@vger.kernel.org Cc: =?UTF-8?q?Ren=C3=A9=20Scharfe?= , Jeff King , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Subject: [PATCH v3 3/5] make object_directory.loose_objects_subdir_seen a bitmap Date: Wed, 7 Jul 2021 23:10:17 +0000 Message-Id: <20210707231019.14738-4-e@80x24.org> In-Reply-To: <20210629205305.7100-1-e@80x24.org> References: <20210629205305.7100-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There's no point in using 8 bits per-directory when 1 bit will do. This saves us 224 bytes per object directory, which ends up being 22MB when dealing with 100K alternates. v2: use bitsizeof() macro and better variable names Signed-off-by: Eric Wong --- object-file.c | 11 ++++++++--- object-store.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/object-file.c b/object-file.c index 2dd70ddf3a..91ded8c22a 100644 --- a/object-file.c +++ b/object-file.c @@ -2461,12 +2461,17 @@ struct oid_array *odb_loose_cache(struct object_directory *odb, { int subdir_nr = oid->hash[0]; struct strbuf buf = STRBUF_INIT; + size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]); + size_t word_index = subdir_nr / word_bits; + size_t mask = 1 << (subdir_nr % word_bits); + uint32_t *bitmap; if (subdir_nr < 0 || - subdir_nr >= ARRAY_SIZE(odb->loose_objects_subdir_seen)) + subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen)) BUG("subdir_nr out of range"); - if (odb->loose_objects_subdir_seen[subdir_nr]) + bitmap = &odb->loose_objects_subdir_seen[word_index]; + if (*bitmap & mask) return &odb->loose_objects_cache[subdir_nr]; strbuf_addstr(&buf, odb->path); @@ -2474,7 +2479,7 @@ struct oid_array *odb_loose_cache(struct object_directory *odb, append_loose_object, NULL, NULL, &odb->loose_objects_cache[subdir_nr]); - odb->loose_objects_subdir_seen[subdir_nr] = 1; + *bitmap |= mask; strbuf_release(&buf); return &odb->loose_objects_cache[subdir_nr]; } diff --git a/object-store.h b/object-store.h index 6077065d90..ab6d469970 100644 --- a/object-store.h +++ b/object-store.h @@ -22,7 +22,7 @@ struct object_directory { * * Be sure to call odb_load_loose_cache() before using. */ - char loose_objects_subdir_seen[256]; + uint32_t loose_objects_subdir_seen[8]; /* 256 bits */ struct oid_array loose_objects_cache[256]; /*