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

Re: [PATCH] lookup_object: remove hashtable_index() and optimize hash_obj()

From
Nicolas Pitre <nico@fluxnic.net>
Date
Sep 12, 2013, 20:08 UTC
Message-ID
<alpine.LFD.2.03.1309121606130.20709@syhkavp.arg>
In-Reply-To
<20130911184845.GA25386@sigill.intra.peff.net>
On Wed, 11 Sep 2013, Jeff King wrote:
Show 15 quoted lines
> On Tue, Sep 10, 2013 at 06:17:12PM -0400, Nicolas Pitre wrote:
> 
> > Also remove the modulus as this is an expansive operation.
> > The size argument is always a power of 2 anyway, so a simple
> > mask operation provides the same result.
> > 
> > On a 'git rev-list --all --objects' run this decreased the time spent
> > in lookup_object from 27.5% to 24.1%.
> 
> Nice. This is a tiny bit subtle, though, as the power-of-2 growth
> happens elsewhere, and we may want to tweak it later (the decorate.c
> hash, for example, grows by 3/2).
> 
> Maybe it's worth squashing in one or both of the comments below as a
> warning to anybody who tries to tweak it.
Agreed.
@Junio: are you willing to squash those in, or do you prefer a resent?
Show 29 quoted lines
> ---
> diff --git a/object.c b/object.c
> index e2dae22..5f792cb 100644
> --- a/object.c
> +++ b/object.c
> @@ -47,6 +47,7 @@ static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
>  {
>  	unsigned int hash;
>  	memcpy(&hash, sha1, sizeof(unsigned int));
> +	/* Assumes power-of-2 hash sizes in grow_object_hash */
>  	return hash & (n - 1);
>  }
>  
> @@ -94,6 +95,10 @@ static void grow_object_hash(void)
>  static void grow_object_hash(void)
>  {
>  	int i;
> +	/*
> +	 * Note that this size must always be power-of-2 to match hash_obj
> +	 * above.
> +	 */
>  	int new_hash_size = obj_hash_size < 32 ? 32 : 2 * obj_hash_size;
>  	struct object **new_hash;
>  
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
Previous: Jeff KingNext: Junio C Hamano
Message 3 of 4 in “lookup_object: remove hashtable_index() and optimize hash_obj()”
  1. lookup_object: remove hashtable_index() and optimize hash_obj()Nicolas Pitre, Sep 10, 2013
  2. Jeff KingSep 11, 2013
  3. Nicolas PitreSep 12, 2013
  4. Junio C HamanoSep 12, 2013

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.