From: Nicolas Pitre <nico@cam.org>
To: David Kastrup <dak@gnu.org>
Cc: git@vger.kernel.org
Subject: Re: Strange code in diff-delta.c
Date: Wed, 22 Aug 2007 21:45:34 -0400 (EDT) [thread overview]
Message-ID: <alpine.LFD.0.999.0708222126590.16727@xanadu.home> (raw)
In-Reply-To: <85k5rnjcbu.fsf@lola.goethe.zz>
On Thu, 23 Aug 2007, David Kastrup wrote:
>
> I am currently looking what can be done to speed up deltaing. The
> following code can be found here:
>
> for (i = 0; i < hsize; i++) {
> if (hash_count[i] < HASH_LIMIT)
> continue;
> entry = hash[i];
> do {
> struct index_entry *keep = entry;
> int skip = hash_count[i] / HASH_LIMIT / 2;
> do {
> entry = entry->next;
> } while(--skip && entry);
> keep->next = entry;
> } while(entry);
> }
>
> If I analyze what happens for various values of hash_count[i], I get
> the following (the first case is by far the worst):
>
> HASH_LIMIT <= hash_count[i] < 2*HASH_LIMIT:
> skip = 0;
> do .. while terminates with negative skip and entry == 0, keep->next
> is set to 0 -> all hashes except the first one get dropped.
> Result is new_hash_count = 1. Ugh, ugh, ugh.
>
> 2*HASH_LIMIT <= hash_count[i] < 4*HASH_LIMIT
> skip = 1;
> do .. while does one iteration, every second value is skipped,
> result is that HASH_LIMIT <= new_hash_count < 2*HASH_LIMIT
>
> 4*HASH_LIMIT <= hash_limit[i] < 6*HASH_LIMIT
> skip = 2;
> do .. while does two iterations, two of three values are skipped,
> result is that 4*HASH_LIMIT/3 <= new_hash_count < 2*HASH_LIMIT
>
> And so on. It would appear that if HASH_LIMIT is supposed to do what
> it is seemingly intended for, the skip calculation has to be just
>
> int skip = hash_count[i] / HASH_LIMIT;
>
> Otherwise, there is completely broken behavior for values between
> HASH_LIMIT and 2*HASH_LIMIT (where only a single hash survives), and
> for larger values, the limit will be 2*HASH_LIMIT rather than
> HASH_LIMIT as was probably intended.
You're absolutely right.
I don't know what I was thinking when I wrote that code, but the /2 is
bogus.
Please send a patch to Junio with my ACK.
Nicolas
next prev parent reply other threads:[~2007-08-23 1:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-23 0:59 Strange code in diff-delta.c David Kastrup
2007-08-23 1:45 ` Nicolas Pitre [this message]
2007-08-23 5:51 ` [PATCH] diff-delta.c: Fix broken skip calculation David Kastrup
2007-08-23 7:06 ` Strange code in diff-delta.c 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=alpine.LFD.0.999.0708222126590.16727@xanadu.home \
--to=nico@cam.org \
--cc=dak@gnu.org \
--cc=git@vger.kernel.org \
/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).