diff mbox series

[v4,06/13] pack-bitmap.c: support bitmap pack-reuse with incremental MIDXs

Message ID 14d3d80c3d301233048004fe9de18154aa597782.1741983492.git.me@ttaylorr.com (mailing list archive)
State Superseded
Headers show
Series midx: incremental multi-pack indexes, part two | expand

Commit Message

Taylor Blau March 14, 2025, 8:18 p.m. UTC
In a similar fashion as previous commits in the first phase of
incremental MIDXs, enumerate not just the packs in the current
incremental MIDX layer, but previous ones as well.

Likewise, in reuse_partial_packfile_from_bitmap(), when reusing only a
single pack from a MIDX, use the oldest layer's preferred pack as it is
likely to contain the most amount of reusable sections.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 pack-bitmap.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Elijah Newren March 18, 2025, 4:13 a.m. UTC | #1
On Fri, Mar 14, 2025 at 1:18 PM Taylor Blau <me@ttaylorr.com> wrote:
>
> In a similar fashion as previous commits in the first phase of
> incremental MIDXs, enumerate not just the packs in the current
> incremental MIDX layer, but previous ones as well.
>
> Likewise, in reuse_partial_packfile_from_bitmap(), when reusing only a
> single pack from a MIDX, use the oldest layer's preferred pack as it is
> likely to contain the most amount of reusable sections.

"most amount" => "largest number" or "largest size" ?


>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
>  pack-bitmap.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/pack-bitmap.c b/pack-bitmap.c
> index 1b4fec0033..7a41535425 100644
> --- a/pack-bitmap.c
> +++ b/pack-bitmap.c
> @@ -2333,7 +2333,8 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
>                 multi_pack_reuse = 0;
>
>         if (multi_pack_reuse) {
> -               for (i = 0; i < bitmap_git->midx->num_packs; i++) {
> +               struct multi_pack_index *m = bitmap_git->midx;
> +               for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
>                         struct bitmapped_pack pack;
>                         if (nth_bitmapped_pack(r, bitmap_git->midx, &pack, i) < 0) {
>                                 warning(_("unable to load pack: '%s', disabling pack-reuse"),
> @@ -2359,14 +2360,18 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
>                 uint32_t pack_int_id;
>
>                 if (bitmap_is_midx(bitmap_git)) {
> +                       struct multi_pack_index *m = bitmap_git->midx;
>                         uint32_t preferred_pack_pos;
>
> -                       if (midx_preferred_pack(bitmap_git->midx, &preferred_pack_pos) < 0) {
> +                       while (m->base_midx)
> +                               m = m->base_midx;
> +
> +                       if (midx_preferred_pack(m, &preferred_pack_pos) < 0) {
>                                 warning(_("unable to compute preferred pack, disabling pack-reuse"));
>                                 return;
>                         }
>
> -                       pack = bitmap_git->midx->packs[preferred_pack_pos];
> +                       pack = nth_midxed_pack(m, preferred_pack_pos);
>                         pack_int_id = preferred_pack_pos;
>                 } else {
>                         pack = bitmap_git->pack;
> --
> 2.49.0.13.gd0d564685b
>
Taylor Blau March 19, 2025, 12:17 a.m. UTC | #2
On Mon, Mar 17, 2025 at 09:13:52PM -0700, Elijah Newren wrote:
> On Fri, Mar 14, 2025 at 1:18 PM Taylor Blau <me@ttaylorr.com> wrote:
> >
> > In a similar fashion as previous commits in the first phase of
> > incremental MIDXs, enumerate not just the packs in the current
> > incremental MIDX layer, but previous ones as well.
> >
> > Likewise, in reuse_partial_packfile_from_bitmap(), when reusing only a
> > single pack from a MIDX, use the oldest layer's preferred pack as it is
> > likely to contain the most amount of reusable sections.
>
> "most amount" => "largest number" or "largest size" ?

Good call; between the two I prefer "largest number".

Thanks,
Taylor
diff mbox series

Patch

diff --git a/pack-bitmap.c b/pack-bitmap.c
index 1b4fec0033..7a41535425 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -2333,7 +2333,8 @@  void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
 		multi_pack_reuse = 0;
 
 	if (multi_pack_reuse) {
-		for (i = 0; i < bitmap_git->midx->num_packs; i++) {
+		struct multi_pack_index *m = bitmap_git->midx;
+		for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
 			struct bitmapped_pack pack;
 			if (nth_bitmapped_pack(r, bitmap_git->midx, &pack, i) < 0) {
 				warning(_("unable to load pack: '%s', disabling pack-reuse"),
@@ -2359,14 +2360,18 @@  void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
 		uint32_t pack_int_id;
 
 		if (bitmap_is_midx(bitmap_git)) {
+			struct multi_pack_index *m = bitmap_git->midx;
 			uint32_t preferred_pack_pos;
 
-			if (midx_preferred_pack(bitmap_git->midx, &preferred_pack_pos) < 0) {
+			while (m->base_midx)
+				m = m->base_midx;
+
+			if (midx_preferred_pack(m, &preferred_pack_pos) < 0) {
 				warning(_("unable to compute preferred pack, disabling pack-reuse"));
 				return;
 			}
 
-			pack = bitmap_git->midx->packs[preferred_pack_pos];
+			pack = nth_midxed_pack(m, preferred_pack_pos);
 			pack_int_id = preferred_pack_pos;
 		} else {
 			pack = bitmap_git->pack;