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

Re: [PATCH] object: measure time needed for resolving hash collisions

From
Jeff King <peff@peff.net>
Date
Sep 15, 2016, 07:01 UTC
Message-ID
<20160915070129.w66dxntm45qngceo@sigill.intra.peff.net>
In-Reply-To
<20160915064701.c4ishixuynbzpgwx@sigill.intra.peff.net>
On Wed, Sep 14, 2016 at 11:47:01PM -0700, Jeff King wrote:
Show 21 quoted lines
> >  	first = i = hash_obj(sha1, obj_hash_size);
> > +	clock_gettime(CLOCK_MONOTONIC, &time1);
> >  	while ((obj = obj_hash[i]) != NULL) {
> >  		if (!hashcmp(sha1, obj->oid.hash))
> >  			break;
> > @@ -98,6 +131,9 @@ struct object *lookup_object(const unsigned char *sha1)
> >  		if (i == obj_hash_size)
> >  			i = 0;
> >  	}
> > +	clock_gettime(CLOCK_MONOTONIC, &time2);
> > +	diff(&time1, &time2, &t_diff);
> > +	add_time_to(&caching, &t_diff);
> >  	if (obj && i != first) {
> 
> I don't think this is actually measuring the time spent on collisions.
> It's measuring the time we spend in hashcmp(), but that includes the
> non-collision case where we find it in the first hashcmp.
> 
> Measuring _just_ the collisions is more like the patch below. In my
> measurements it's more like 30ms, compared to 10s for all of the
> hashcmps.

I forgot to send the patch. Which is just as well, because I realized it was totally buggy.

Here's a patch that I believe is correct (it counts only times when we move past the first hash slot). It spends about 280ms. Which is still a lot less than 10s, so I think my other comments stand.

---
diff --git a/object.c b/object.c
index e9e73e0..7a74a1d 100644
--- a/object.c
+++ b/object.c
@@ -123,17 +123,20 @@ struct object *lookup_object(const unsigned char *sha1)
 		return NULL;
 
 	first = i = hash_obj(sha1, obj_hash_size);
-	clock_gettime(CLOCK_MONOTONIC, &time1);
 	while ((obj = obj_hash[i]) != NULL) {
 		if (!hashcmp(sha1, obj->oid.hash))
 			break;
+		if (first == i)
+			clock_gettime(CLOCK_MONOTONIC, &time1);
 		i++;
 		if (i == obj_hash_size)
 			i = 0;
 	}
-	clock_gettime(CLOCK_MONOTONIC, &time2);
-	diff(&time1, &time2, &t_diff);
-	add_time_to(&caching, &t_diff);
+	if (i != first) {
+		clock_gettime(CLOCK_MONOTONIC, &time2);
+		diff(&time1, &time2, &t_diff);
+		add_time_to(&caching, &t_diff);
+	}
 	if (obj && i != first) {
 		/*
 		 * Move object to where we started to look for it so
Previous: Jeff KingNext: Stefan Beller
Message 3 of 7 in “object: measure time needed for resolving hash collisions”
  1. object: measure time needed for resolving hash collisionsStefan Beller, Sep 15, 2016
  2. Jeff KingSep 15, 2016
  3. Jeff KingSep 15, 2016
  4. Stefan BellerSep 15, 2016
  5. Jeff KingSep 15, 2016
  6. Junio C HamanoSep 15, 2016
  7. Jeff KingSep 15, 2016

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.