Skip to content

Commit 4cea1ce

Browse files
rscharfegitster
authored andcommitted
object-store: use one oid_array per subdirectory for loose cache
The loose objects cache is filled one subdirectory at a time as needed. It is stored in an oid_array, which has to be resorted after each add operation. So when querying a wide range of objects, the partially filled array needs to be resorted up to 255 times, which takes over 100 times longer than sorting once. Use one oid_array for each subdirectory. This ensures that entries have to only be sorted a single time. It also avoids eight binary search steps for each cache lookup as a small bonus. The cache is used for collision checks for the log placeholders %h, %t and %p, and we can see the change speeding them up in a repository with ca. 100 objects per subdirectory: $ git count-objects 26733 objects, 68808 kilobytes Test HEAD^ HEAD -------------------------------------------------------------------- 4205.1: log with %H 0.51(0.47+0.04) 0.51(0.49+0.02) +0.0% 4205.2: log with %h 0.84(0.82+0.02) 0.60(0.57+0.03) -28.6% 4205.3: log with %T 0.53(0.49+0.04) 0.52(0.48+0.03) -1.9% 4205.4: log with %t 0.84(0.80+0.04) 0.60(0.59+0.01) -28.6% 4205.5: log with %P 0.52(0.48+0.03) 0.51(0.50+0.01) -1.9% 4205.6: log with %p 0.85(0.78+0.06) 0.61(0.56+0.05) -28.2% 4205.7: log with %h-%h-%h 0.96(0.92+0.03) 0.69(0.64+0.04) -28.1% Reported-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d4e19e5 commit 4cea1ce

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

object-store.h

Lines changed: 1 addition & 1 deletion
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,

sha1-file.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@ struct oid_array *odb_loose_cache(struct object_directory *odb,
21552155
{
21562156
int subdir_nr = oid->hash[0];
21572157
odb_load_loose_cache(odb, subdir_nr);
2158-
return &odb->loose_objects_cache;
2158+
return &odb->loose_objects_cache[subdir_nr];
21592159
}
21602160

21612161
void odb_load_loose_cache(struct object_directory *odb, int subdir_nr)
@@ -2173,14 +2173,17 @@ void odb_load_loose_cache(struct object_directory *odb, int subdir_nr)
21732173
for_each_file_in_obj_subdir(subdir_nr, &buf,
21742174
append_loose_object,
21752175
NULL, NULL,
2176-
&odb->loose_objects_cache);
2176+
&odb->loose_objects_cache[subdir_nr]);
21772177
odb->loose_objects_subdir_seen[subdir_nr] = 1;
21782178
strbuf_release(&buf);
21792179
}
21802180

21812181
void odb_clear_loose_cache(struct object_directory *odb)
21822182
{
2183-
oid_array_clear(&odb->loose_objects_cache);
2183+
int i;
2184+
2185+
for (i = 0; i < ARRAY_SIZE(odb->loose_objects_cache); i++)
2186+
oid_array_clear(&odb->loose_objects_cache[i]);
21842187
memset(&odb->loose_objects_subdir_seen, 0,
21852188
sizeof(odb->loose_objects_subdir_seen));
21862189
}

0 commit comments

Comments
 (0)