Skip to content

Commit eb8638a

Browse files
committed
Merge branch 'rs/loose-object-cache-perffix'
The loose object cache used to optimize existence look-up has been updated. * rs/loose-object-cache-perffix: object-store: retire odb_load_loose_cache() object-store: use one oid_array per subdirectory for loose cache object-store: factor out odb_clear_loose_cache() object-store: factor out odb_loose_cache()
2 parents 702bbfe + 8be88db commit eb8638a

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

object-store.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct object_directory {
2020
* Be sure to call odb_load_loose_cache() before using.
2121
*/
2222
char loose_objects_subdir_seen[256];
23-
struct oid_array loose_objects_cache;
23+
struct oid_array loose_objects_cache[256];
2424

2525
/*
2626
* Path to the alternative object store. If this is a relative path,
@@ -48,11 +48,14 @@ void add_to_alternates_file(const char *dir);
4848
void add_to_alternates_memory(const char *dir);
4949

5050
/*
51-
* Populate an odb's loose object cache for one particular subdirectory (i.e.,
52-
* the one that corresponds to the first byte of objects you're interested in,
53-
* from 0 to 255 inclusive).
51+
* Populate and return the loose object cache array corresponding to the
52+
* given object ID.
5453
*/
55-
void odb_load_loose_cache(struct object_directory *odb, int subdir_nr);
54+
struct oid_array *odb_loose_cache(struct object_directory *odb,
55+
const struct object_id *oid);
56+
57+
/* Empty the loose object cache for the specified object directory. */
58+
void odb_clear_loose_cache(struct object_directory *odb);
5659

5760
struct packed_git {
5861
struct packed_git *next;

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ struct raw_object_store *raw_object_store_new(void)
485485
static void free_object_directory(struct object_directory *odb)
486486
{
487487
free(odb->path);
488-
oid_array_clear(&odb->loose_objects_cache);
488+
odb_clear_loose_cache(odb);
489489
free(odb);
490490
}
491491

packfile.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -994,11 +994,8 @@ void reprepare_packed_git(struct repository *r)
994994
{
995995
struct object_directory *odb;
996996

997-
for (odb = r->objects->odb; odb; odb = odb->next) {
998-
oid_array_clear(&odb->loose_objects_cache);
999-
memset(&odb->loose_objects_subdir_seen, 0,
1000-
sizeof(odb->loose_objects_subdir_seen));
1001-
}
997+
for (odb = r->objects->odb; odb; odb = odb->next)
998+
odb_clear_loose_cache(odb);
1002999

10031000
r->objects->approximate_object_count_valid = 0;
10041001
r->objects->packed_git_initialized = 0;

sha1-file.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,16 +924,14 @@ static int open_sha1_file(struct repository *r,
924924
static int quick_has_loose(struct repository *r,
925925
const unsigned char *sha1)
926926
{
927-
int subdir_nr = sha1[0];
928927
struct object_id oid;
929928
struct object_directory *odb;
930929

931930
hashcpy(oid.hash, sha1);
932931

933932
prepare_alt_odb(r);
934933
for (odb = r->objects->odb; odb; odb = odb->next) {
935-
odb_load_loose_cache(odb, subdir_nr);
936-
if (oid_array_lookup(&odb->loose_objects_cache, &oid) >= 0)
934+
if (oid_array_lookup(odb_loose_cache(odb, &oid), &oid) >= 0)
937935
return 1;
938936
}
939937
return 0;
@@ -2152,24 +2150,37 @@ static int append_loose_object(const struct object_id *oid, const char *path,
21522150
return 0;
21532151
}
21542152

2155-
void odb_load_loose_cache(struct object_directory *odb, int subdir_nr)
2153+
struct oid_array *odb_loose_cache(struct object_directory *odb,
2154+
const struct object_id *oid)
21562155
{
2156+
int subdir_nr = oid->hash[0];
21572157
struct strbuf buf = STRBUF_INIT;
21582158

21592159
if (subdir_nr < 0 ||
21602160
subdir_nr >= ARRAY_SIZE(odb->loose_objects_subdir_seen))
21612161
BUG("subdir_nr out of range");
21622162

21632163
if (odb->loose_objects_subdir_seen[subdir_nr])
2164-
return;
2164+
return &odb->loose_objects_cache[subdir_nr];
21652165

21662166
strbuf_addstr(&buf, odb->path);
21672167
for_each_file_in_obj_subdir(subdir_nr, &buf,
21682168
append_loose_object,
21692169
NULL, NULL,
2170-
&odb->loose_objects_cache);
2170+
&odb->loose_objects_cache[subdir_nr]);
21712171
odb->loose_objects_subdir_seen[subdir_nr] = 1;
21722172
strbuf_release(&buf);
2173+
return &odb->loose_objects_cache[subdir_nr];
2174+
}
2175+
2176+
void odb_clear_loose_cache(struct object_directory *odb)
2177+
{
2178+
int i;
2179+
2180+
for (i = 0; i < ARRAY_SIZE(odb->loose_objects_cache); i++)
2181+
oid_array_clear(&odb->loose_objects_cache[i]);
2182+
memset(&odb->loose_objects_subdir_seen, 0,
2183+
sizeof(odb->loose_objects_subdir_seen));
21732184
}
21742185

21752186
static int check_stream_sha1(git_zstream *stream,

sha1-name.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ static int match_sha(unsigned, const unsigned char *, const unsigned char *);
8787

8888
static void find_short_object_filename(struct disambiguate_state *ds)
8989
{
90-
int subdir_nr = ds->bin_pfx.hash[0];
9190
struct object_directory *odb;
9291

9392
for (odb = the_repository->objects->odb;
9493
odb && !ds->ambiguous;
9594
odb = odb->next) {
9695
int pos;
96+
struct oid_array *loose_objects;
9797

98-
odb_load_loose_cache(odb, subdir_nr);
99-
pos = oid_array_lookup(&odb->loose_objects_cache, &ds->bin_pfx);
98+
loose_objects = odb_loose_cache(odb, &ds->bin_pfx);
99+
pos = oid_array_lookup(loose_objects, &ds->bin_pfx);
100100
if (pos < 0)
101101
pos = -1 - pos;
102-
while (!ds->ambiguous && pos < odb->loose_objects_cache.nr) {
102+
while (!ds->ambiguous && pos < loose_objects->nr) {
103103
const struct object_id *oid;
104-
oid = odb->loose_objects_cache.oid + pos;
104+
oid = loose_objects->oid + pos;
105105
if (!match_sha(ds->len, ds->bin_pfx.hash, oid->hash))
106106
break;
107107
update_candidates(ds, oid);

0 commit comments

Comments
 (0)