git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 2/2] reftable/block: fix binary search over restart counter
Date: Thu, 07 Mar 2024 15:29:07 -0800	[thread overview]
Message-ID: <xmqq7cidk4e4.fsf@gitster.g> (raw)
In-Reply-To: <370b608f9007abe9c0562d76894e2475d19867a1.1709843663.git.ps@pks.im> (Patrick Steinhardt's message of "Thu, 7 Mar 2024 21:36:02 +0100")

Patrick Steinhardt <ps@pks.im> writes:

> The consequence is that `binsearch()` essentially always returns 0,
> indicacting to us that we must start searching right at the beginning of
> the block. This works by chance because we now always do a linear scan
> from the start of the block, and thus we would still end up finding the
> desired record. But needless to say, this makes the optimization quite
> useless.
>
> Fix this bug by returning whether the current key is smaller than the
> searched key. As the current behaviour was correct it is not possible to
> write a test. Furthermore it is also not really possible to demonstrate
> in a benchmark that this fix speeds up seeking records.

This is an amusing bug.  

I wonder if we inherited it from the original implementation---this
was imported from jgit, right?

Thanks for a detailed write-up.  

The "it is a fix, but the breakage is well hidden and cannot be
observed only by checking for correctness" aspect of the bug
deserves the unusually large "number of paragraphs explaining the
change divided by number of changed lines" ratio ;-).

Applied.

> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  reftable/block.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/reftable/block.c b/reftable/block.c
> index 72eb73b380..1663030386 100644
> --- a/reftable/block.c
> +++ b/reftable/block.c
> @@ -302,7 +302,7 @@ static int restart_key_less(size_t idx, void *args)
>  
>  	result = strbuf_cmp(&a->key, &rkey);
>  	strbuf_release(&rkey);
> -	return result;
> +	return result < 0;
>  }
>  
>  void block_iter_copy_from(struct block_iter *dest, struct block_iter *src)

  reply	other threads:[~2024-03-07 23:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 15:26 [PATCH] reftable/block: fix binary search over restart counter Patrick Steinhardt
2024-03-07 16:24 ` Patrick Steinhardt
2024-03-07 20:35 ` [PATCH v2 0/2] " Patrick Steinhardt
2024-03-07 20:35   ` [PATCH v2 1/2] reftable/record: fix memory leak when decoding object records Patrick Steinhardt
2024-03-07 20:36   ` [PATCH v2 2/2] reftable/block: fix binary search over restart counter Patrick Steinhardt
2024-03-07 23:29     ` Junio C Hamano [this message]
2024-03-08  0:40       ` Junio C Hamano
2024-03-11  5:18         ` Patrick Steinhardt
2024-03-11 17:33           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7cidk4e4.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).