Skip to content

Commit db40e3c

Browse files
ttaylorrgitster
authored andcommitted
pack-bitmap.c: avoid repeated pack_pos_to_offset() during reuse
When calling `try_partial_reuse()`, the (sole) caller from the function `reuse_partial_packfile_from_bitmap_1()` has to translate its bit position to a pack position. In the MIDX bitmap case, the caller translates from the bit position, to a position in the MIDX's pseudo-pack order (with `pack_pos_to_midx()`), then get a pack offset (with `nth_midxed_offset()`) before finally working backwards to get the pack position in the source pack by calling `offset_to_pack_pos()`. In the non-MIDX bitmap case, we can use the bit position as the pack position directly (see the comment at the beginning of the `reuse_partial_packfile_from_bitmap_1()` function for why). In either case, the first thing that `try_partial_reuse()` does after being called is determine the offset of the object at the given pack position by calling `pack_pos_to_offset()`. But we already have that information in the MIDX case! Avoid re-computing that information by instead passing it in. In the MIDX case, we already have that information stored. In the non-MIDX case, the call to `pack_pos_to_offset()` moves from the function `try_partial_reuse()` to its caller. In total, we'll save one call to `pack_pos_to_offset()` when processing MIDX bitmaps. (On my machine, there is a slight speed-up on the order of ~2ms, but it is within the margin of error over 10 runs, so I think you'd have to have a truly gigantic repository to confidently measure any significant improvement here). Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 125c326 commit db40e3c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pack-bitmap.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,17 +2055,18 @@ static int try_partial_reuse(struct bitmap_index *bitmap_git,
20552055
struct bitmapped_pack *pack,
20562056
size_t bitmap_pos,
20572057
uint32_t pack_pos,
2058+
off_t offset,
20582059
struct bitmap *reuse,
20592060
struct pack_window **w_curs)
20602061
{
2061-
off_t offset, delta_obj_offset;
2062+
off_t delta_obj_offset;
20622063
enum object_type type;
20632064
unsigned long size;
20642065

20652066
if (pack_pos >= pack->p->num_objects)
20662067
return -1; /* not actually in the pack */
20672068

2068-
offset = delta_obj_offset = pack_pos_to_offset(pack->p, pack_pos);
2069+
delta_obj_offset = offset;
20692070
type = unpack_object_header(pack->p, w_curs, &offset, &size);
20702071
if (type < 0)
20712072
return -1; /* broken packfile, punt */
@@ -2184,6 +2185,7 @@ static void reuse_partial_packfile_from_bitmap_1(struct bitmap_index *bitmap_git
21842185
for (offset = 0; offset < BITS_IN_EWORD; offset++) {
21852186
size_t bit_pos;
21862187
uint32_t pack_pos;
2188+
off_t ofs;
21872189

21882190
if (word >> offset == 0)
21892191
break;
@@ -2198,7 +2200,6 @@ static void reuse_partial_packfile_from_bitmap_1(struct bitmap_index *bitmap_git
21982200

21992201
if (bitmap_is_midx(bitmap_git)) {
22002202
uint32_t midx_pos;
2201-
off_t ofs;
22022203

22032204
midx_pos = pack_pos_to_midx(bitmap_git->midx, bit_pos);
22042205
ofs = nth_midxed_offset(bitmap_git->midx, midx_pos);
@@ -2213,10 +2214,12 @@ static void reuse_partial_packfile_from_bitmap_1(struct bitmap_index *bitmap_git
22132214
BUG("advanced beyond the end of pack %s (%"PRIuMAX" > %"PRIu32")",
22142215
pack_basename(pack->p), (uintmax_t)pack_pos,
22152216
pack->p->num_objects);
2217+
2218+
ofs = pack_pos_to_offset(pack->p, pack_pos);
22162219
}
22172220

22182221
if (try_partial_reuse(bitmap_git, pack, bit_pos,
2219-
pack_pos, reuse, &w_curs) < 0) {
2222+
pack_pos, ofs, reuse, &w_curs) < 0) {
22202223
/*
22212224
* try_partial_reuse indicated we couldn't reuse
22222225
* any bits, so there is no point in trying more

0 commit comments

Comments
 (0)