Skip to content

Commit ee1c6c3

Browse files
peffgitster
authored andcommitted
sha1_file: only freshen packs once per run
Since 33d4221 (write_sha1_file: freshen existing objects, 2014-10-15), we update the mtime of existing objects that we would have written out (had they not existed). For the common case in which many objects are packed, we may update the mtime on a single packfile repeatedly. This can result in a noticeable performance problem if calling utime() is expensive (e.g., because your storage is on NFS). We can fix this by keeping a per-pack flag that lets us freshen only once per program invocation. An alternative would be to keep the packed_git.mtime flag up to date as we freshen, and freshen only once every N seconds. In practice, it's not worth the complexity. We are racing against prune expiration times here, which inherently must be set to accomodate reasonable program running times (because they really care about the time between an object being written and it becoming referenced, and the latter is typically the last step a program takes). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b5f52f3 commit ee1c6c3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ extern struct packed_git {
11681168
int pack_fd;
11691169
unsigned pack_local:1,
11701170
pack_keep:1,
1171+
freshened:1,
11711172
do_not_close:1;
11721173
unsigned char sha1[20];
11731174
/* something like ".git/objects/pack/xxxxx.pack" */

sha1_file.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2999,7 +2999,14 @@ static int freshen_loose_object(const unsigned char *sha1)
29992999
static int freshen_packed_object(const unsigned char *sha1)
30003000
{
30013001
struct pack_entry e;
3002-
return find_pack_entry(sha1, &e) && freshen_file(e.p->pack_name);
3002+
if (!find_pack_entry(sha1, &e))
3003+
return 0;
3004+
if (e.p->freshened)
3005+
return 1;
3006+
if (!freshen_file(e.p->pack_name))
3007+
return 0;
3008+
e.p->freshened = 1;
3009+
return 1;
30033010
}
30043011

30053012
int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *returnsha1)

0 commit comments

Comments
 (0)