make object_directory.loose_objects_subdir_seen a bitmap

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. Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Jul 7, 2021 at 23:10 UTC 33f379eee63a0529f85079857598ac6325d3aec5
2 files changed +9 -4
object-file.c
+8 -3
@@ -2461,12 +2461,17 @@ struct oid_array *odb_loose_cache(struct object_directory *odb,
2461 {
2462 int subdir_nr = oid->hash[0];
2463 struct strbuf buf = STRBUF_INIT;
2464 + size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
2465 + size_t word_index = subdir_nr / word_bits;
2466 + size_t mask = 1 << (subdir_nr % word_bits);
2467 + uint32_t *bitmap;
2468
2469 if (subdir_nr < 0 ||
2466 - subdir_nr >= ARRAY_SIZE(odb->loose_objects_subdir_seen))
2470 + subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
2471 BUG("subdir_nr out of range");
2472
2469 - if (odb->loose_objects_subdir_seen[subdir_nr])
2473 + bitmap = &odb->loose_objects_subdir_seen[word_index];
2474 + if (*bitmap & mask)
2475 return &odb->loose_objects_cache[subdir_nr];
2476
2477 strbuf_addstr(&buf, odb->path);
@@ -2474,7 +2479,7 @@ struct oid_array *odb_loose_cache(struct object_directory *odb,
2479 append_loose_object,
2480 NULL, NULL,
2481 &odb->loose_objects_cache[subdir_nr]);
2477 - odb->loose_objects_subdir_seen[subdir_nr] = 1;
2482 + *bitmap |= mask;
2483 strbuf_release(&buf);
2484 return &odb->loose_objects_cache[subdir_nr];
2485 }
object-store.h
+1 -1
@@ -22,7 +22,7 @@ struct object_directory {
22 *
23 * Be sure to call odb_load_loose_cache() before using.
24 */
25 - char loose_objects_subdir_seen[256];
25 + uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
26 struct oid_array loose_objects_cache[256];
27
28 /*