Skip to content

Commit 5ff2969

Browse files
pks-tgitster
authored andcommitted
packfile: skip unpacking object header for disk size requests
While most of the object info requests for a packed object require us to unpack its headers, reading its disk size doesn't. We still unpack the object header in that case though, which is unnecessary work. Skip reading the header if only the disk size is requested. This leads to a small speedup when reading disk size, only. The following benchmark was done in the Git repository: Benchmark 1: ./git rev-list --disk-usage HEAD (rev = HEAD~) Time (mean ± σ): 105.2 ms ± 0.6 ms [User: 91.4 ms, System: 13.3 ms] Range (min … max): 103.7 ms … 106.0 ms 27 runs Benchmark 2: ./git rev-list --disk-usage HEAD (rev = HEAD) Time (mean ± σ): 96.7 ms ± 0.4 ms [User: 86.2 ms, System: 10.0 ms] Range (min … max): 96.2 ms … 98.1 ms 30 runs Summary ./git rev-list --disk-usage HEAD (rev = HEAD) ran 1.09 ± 0.01 times faster than ./git rev-list --disk-usage HEAD (rev = HEAD~) Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8908c30 commit 5ff2969

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packfile.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
15861586
struct pack_window *w_curs = NULL;
15871587
unsigned long size;
15881588
off_t curpos = obj_offset;
1589-
enum object_type type;
1589+
enum object_type type = OBJ_NONE;
15901590
int ret;
15911591

15921592
/*
@@ -1598,7 +1598,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
15981598
&type);
15991599
if (!*oi->contentp)
16001600
type = OBJ_BAD;
1601-
} else {
1601+
} else if (oi->sizep || oi->typep || oi->delta_base_oid) {
16021602
type = unpack_object_header(p, &w_curs, &curpos, &size);
16031603
}
16041604

@@ -1662,6 +1662,9 @@ int packed_object_info(struct repository *r, struct packed_git *p,
16621662
oi->u.packed.pack = p;
16631663

16641664
switch (type) {
1665+
case OBJ_NONE:
1666+
oi->u.packed.type = PACKED_OBJECT_TYPE_UNKNOWN;
1667+
break;
16651668
case OBJ_REF_DELTA:
16661669
oi->u.packed.type = PACKED_OBJECT_TYPE_REF_DELTA;
16671670
break;

0 commit comments

Comments
 (0)