git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Keep last used delta base in the delta window

From
Nicolas Pitre <nico@cam.org>
Date
Aug 29, 2007, 18:21 UTC
Message-ID
<alpine.LFD.0.999.0708291339580.16727@xanadu.home>
In-Reply-To
<7vy7fxyy52.fsf@gitster.siamese.dyndns.org>
On Mon, 27 Aug 2007, Junio C Hamano wrote:
Show 9 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > Instead of treating the "the last used one happened to be on the
> > horizon -- try not to drop it" special case, I wonder if it
> > makes sense to float the last used delta base object early in
> > the window _after_ it is used.  Wouldn't we keep more than one
> > very recently used delta base objects in the window that way?
> 
> The attached is my quick-and-dirty one.  

I like this. A LRU sorting of base objects is obviously a good thing to do. Some comments below.

[...]
Show 26 quoted lines
> diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
> index 9b3ef94..2a5ea29 100644
> --- a/builtin-pack-objects.c
> +++ b/builtin-pack-objects.c
> @@ -1439,6 +1439,61 @@ static void free_unpacked(struct unpacked *n)
>  	n->depth = 0;
>  }
>  
> +static void shift_base(int idx, int window, struct unpacked *array, struct object_entry *delta_base)
> +{
> +	/*
> +	 * The delta_base was a useful one to deltify the object at
> +	 * idx (circular).  Shift the contents of array (circular
> +	 * buffer) so that it will be evicted last.
> +	 */
> +	int good_base, good_at;
> +	struct unpacked swap;
> +
> +	for (good_base = 0; good_base < window; good_base++)
> +		if (array[good_base].entry == delta_base)
> +			break;
> +	if (window <= good_base)
> +		die("Junio is an idiot");
> +
> +	if (window <= ++idx)
> +		idx = 0;

<ranting again> I cannot do otherwise but hate this notation. Just for this one I had to spend at least 5 seconds thinking about it before I could convince myself it is OK. It annoyed me so much that I switched the condition around in my local copy. I acknowledge your maintainer priviledges, but I couldn't stop myself making noise about this again anyway. </ranting again>

Show 12 quoted lines
> +	/*
> +	 * The entry at idx modulo window will be evicted first during
> +	 * the next round.  Where in the next window is the good_base
> +	 * found?
> +	 */
> +	good_at = (good_base + window - idx) % window;
> +
> +	/*
> +	 * If it is already at the furthest edge, nothing needs to be done.
> +	 */
> +	if (good_at == window - 1)
> +		return;

This condition will never occur because, upon entering this function, idx points to the _current_ object which is never considered as a base (can't deltify against self). So you probably should avoid increasing idx.

Yet I think it would be clearer if you had this instead (assuming idx unchanged):

	/* How far is the good base from the front of the window? */
	good_dist = (window + idx - good_base) % window;
	/* If it is already at the furthest edge, nothing needs to be done. */
	if (good_dist <= 1)
		return;
	/* Otherwise, stash it away, shift the others down and swap it in. */
	swap = array[good_base];
	dst = good_base;
	while (--good_dist > 0) {
		src = (dst + 1) % window;
		array[dst] = array[src];
		dst = src;
	}
	array[dst] = swap;
> +	swap = array[good_base];
> +
> +	while (good_at < window) {

This also had the effect of moving down the current object, i.e. the one that was just deltified. Maybe this is a good thing, in which case the "if (good_dist <= 1)" above can be deleted and "while (good_dist-- > 0)" used instead.

Nicolas
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 9 in “Keep last used delta base in the delta window”
  1. Keep last used delta base in the delta windowMartin Koegler, Aug 26, 2007
  2. Junio C HamanoAug 27, 2007
  3. David KastrupAug 27, 2007
  4. Martin KoeglerAug 27, 2007
  5. David KastrupAug 27, 2007
  6. Junio C HamanoAug 27, 2007
  7. Nicolas PitreAug 29, 2007
  8. Junio C HamanoAug 29, 2007
  9. Nicolas PitreAug 29, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.