Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-02 Thread Jeff King
On Fri, May 03, 2013 at 02:02:44AM -0400, Jeff King wrote: > > Can we be sure that the function is never invoked in concurrently from > > different threads? I attempted to audit code paths, but quickly gave up > > because I know too little about this machinery. > > I didn't check explicitly, but

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-02 Thread Jeff King
On Fri, May 03, 2013 at 07:59:09AM +0200, Johannes Sixt wrote: > Am 5/2/2013 17:46, schrieb Jeff King: > > On Thu, May 02, 2013 at 09:05:01AM +0200, Johannes Sixt wrote: > >> BTW, do you notice that the function is now modifying an object (the hash > >> table) even though this is rather unexpected

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-02 Thread Johannes Sixt
Am 5/2/2013 17:46, schrieb Jeff King: > On Thu, May 02, 2013 at 09:05:01AM +0200, Johannes Sixt wrote: >> BTW, do you notice that the function is now modifying an object (the hash >> table) even though this is rather unexpected from a "lookup" function? > > I think this is fine. The function is co

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-02 Thread Jeff King
On Thu, May 02, 2013 at 08:46:08AM -0700, Junio C Hamano wrote: > Johannes Sixt writes: > > > BTW, do you notice that the function is now modifying an object (the hash > > table) even though this is rather unexpected from a "lookup" function? > > At the philosophical level, "lookup" ought to be

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-02 Thread Jeff King
On Thu, May 02, 2013 at 09:05:01AM +0200, Johannes Sixt wrote: > > I figured the lengthy description in the commit message would be > > sufficient, > > It's absolutely sufficient *if* one reads the commit message. In this > case, though it goes more like "this function should be trivial, and it i

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-02 Thread Junio C Hamano
Johannes Sixt writes: > BTW, do you notice that the function is now modifying an object (the hash > table) even though this is rather unexpected from a "lookup" function? At the philosophical level, "lookup" ought to be operating on a "const" table. But at the implementation level, the table do

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-02 Thread Junio C Hamano
Jeff King writes: > I figured the lengthy description in the commit message would be > sufficient, but I don't mind adding something like your suggestion to > point readers of the code in the right direction when they see it. Yeah, I'll squash J6t's comment in and requeue. If somebody is learni

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-02 Thread Johannes Sixt
Am 5/2/2013 8:46, schrieb Jeff King: > On Thu, May 02, 2013 at 08:44:07AM +0200, Johannes Sixt wrote: >> Am 5/1/2013 22:34, schrieb Jeff King: >>> struct object *lookup_object(const unsigned char *sha1) >>> { >>> - unsigned int i; >>> + unsigned int i, first; >>> struct object *obj; >>>

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-01 Thread Jeff King
On Thu, May 02, 2013 at 08:44:07AM +0200, Johannes Sixt wrote: > Am 5/1/2013 22:34, schrieb Jeff King: > > struct object *lookup_object(const unsigned char *sha1) > > { > > - unsigned int i; > > + unsigned int i, first; > > struct object *obj; > > > > if (!obj_hash) > >

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-01 Thread Johannes Sixt
Am 5/1/2013 22:34, schrieb Jeff King: > struct object *lookup_object(const unsigned char *sha1) > { > - unsigned int i; > + unsigned int i, first; > struct object *obj; > > if (!obj_hash) > return NULL; > > - i = hashtable_index(sha1); > + first = i =

Re: [PATCH] lookup_object: prioritize recently found objects

2013-05-01 Thread Junio C Hamano
Jeff King writes: > We could instead bump X into the `i` slot, and then shift > the whole contiguous chain down by one, resulting in: > > index | i-1 | i | i+1 | i+2 | >--- > entry ... | A | X | B | C | ... >---

[PATCH] lookup_object: prioritize recently found objects

2013-05-01 Thread Jeff King
The lookup_object function is backed by a hash table of all objects we have seen in the program. We manage collisions with a linear walk over the colliding entries, checking each with hashcmp(). The main cost of lookup is in these hashcmp() calls; finding our item in the first slot is cheaper than