diff mbox series

[RFC,05/10] pack-bitmap: don't rely on bitmap_git->reuse_objects

Message ID 20190913130226.7449-6-chriscool@tuxfamily.org (mailing list archive)
State New, archived
Headers show
Series Rewrite packfile reuse code | expand

Commit Message

Christian Couder Sept. 13, 2019, 1:02 p.m. UTC
From: Jeff King <peff@peff.net>

As we now allocate 2 more words than necessary for each
bitmap to serve as marks telling us that we can stop
iterating over the words, we don't need to rely on
bitmap_git->reuse_objects to stop iterating over the words.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 pack-bitmap.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

Comments

Jonathan Tan Oct. 10, 2019, 11:44 p.m. UTC | #1
> As we now allocate 2 more words than necessary for each
> bitmap to serve as marks telling us that we can stop
> iterating over the words, we don't need to rely on
> bitmap_git->reuse_objects to stop iterating over the words.

As Peff states [1], this justification is probably incorrect as well.
The actual justification seems to be that we will no longer compute
reuse_objects (in a future patch), so we cannot rely on it anymore to
terminate the loop early; we have to iterate to the end.

[1] https://public-inbox.org/git/20191002155721.GD6116@sigill.intra.peff.net/

> @@ -622,7 +622,7 @@ static void show_objects_for_type(
>  	enum object_type object_type,
>  	show_reachable_fn show_reach)
>  {
> -	size_t pos = 0, i = 0;
> +	size_t i = 0;
>  	uint32_t offset;
>  
>  	struct ewah_iterator it;
> @@ -630,13 +630,15 @@ static void show_objects_for_type(
>  
>  	struct bitmap *objects = bitmap_git->result;
>  
> -	if (bitmap_git->reuse_objects == bitmap_git->pack->num_objects)
> -		return;
> -
>  	ewah_iterator_init(&it, type_filter);
>  
> -	while (i < objects->word_alloc && ewah_iterator_next(&filter, &it)) {
> +	for (i = 0; i < objects->word_alloc &&
> +			ewah_iterator_next(&filter, &it); i++) {
>  		eword_t word = objects->words[i] & filter;
> +		size_t pos = (i * BITS_IN_EWORD);
> +
> +		if (!word)
> +			continue;

Here, iteration is not terminated when we see a 0. We just proceed to
the next one.
Christian Couder Oct. 11, 2019, 7:50 a.m. UTC | #2
On Fri, Oct 11, 2019 at 1:44 AM Jonathan Tan <jonathantanmy@google.com> wrote:
>
> > As we now allocate 2 more words than necessary for each
> > bitmap to serve as marks telling us that we can stop
> > iterating over the words, we don't need to rely on
> > bitmap_git->reuse_objects to stop iterating over the words.
>
> As Peff states [1], this justification is probably incorrect as well.
> The actual justification seems to be that we will no longer compute
> reuse_objects (in a future patch), so we cannot rely on it anymore to
> terminate the loop early; we have to iterate to the end.
>
> [1] https://public-inbox.org/git/20191002155721.GD6116@sigill.intra.peff.net/

Ok, thanks! I will change the description.
diff mbox series

Patch

diff --git a/pack-bitmap.c b/pack-bitmap.c
index ed2befaac6..b2422fed8f 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -622,7 +622,7 @@  static void show_objects_for_type(
 	enum object_type object_type,
 	show_reachable_fn show_reach)
 {
-	size_t pos = 0, i = 0;
+	size_t i = 0;
 	uint32_t offset;
 
 	struct ewah_iterator it;
@@ -630,13 +630,15 @@  static void show_objects_for_type(
 
 	struct bitmap *objects = bitmap_git->result;
 
-	if (bitmap_git->reuse_objects == bitmap_git->pack->num_objects)
-		return;
-
 	ewah_iterator_init(&it, type_filter);
 
-	while (i < objects->word_alloc && ewah_iterator_next(&filter, &it)) {
+	for (i = 0; i < objects->word_alloc &&
+			ewah_iterator_next(&filter, &it); i++) {
 		eword_t word = objects->words[i] & filter;
+		size_t pos = (i * BITS_IN_EWORD);
+
+		if (!word)
+			continue;
 
 		for (offset = 0; offset < BITS_IN_EWORD; ++offset) {
 			struct object_id oid;
@@ -648,9 +650,6 @@  static void show_objects_for_type(
 
 			offset += ewah_bit_ctz64(word >> offset);
 
-			if (pos + offset < bitmap_git->reuse_objects)
-				continue;
-
 			entry = &bitmap_git->pack->revindex[pos + offset];
 			nth_packed_object_oid(&oid, bitmap_git->pack, entry->nr);
 
@@ -659,9 +658,6 @@  static void show_objects_for_type(
 
 			show_reach(&oid, object_type, 0, hash, bitmap_git->pack, entry->offset);
 		}
-
-		pos += BITS_IN_EWORD;
-		i++;
 	}
 }