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

Re: [PATCH 3/4] Use binary searching on large buckets in git-describe.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 14, 2007, 23:07 UTC
Message-ID
<20070114230721.GD10888@spearce.org>
In-Reply-To
<7v3b6dh19y.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
Show 9 quoted lines
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > If a project has a really huge number of tags (such as several
> > thousand tags) then we are likely to have nearly a hundred tags in
> > some buckets.  Scanning those buckets as linked lists could take
> > a large amount of time if done repeatedly during history traversal.
> 
> I think this is a good idea -- but would you still need the 256
> buckets if you do this?

Well, yes and no. The binary search would make it O(log N) rather than O(N), which is clearly an improvement. But we're hashing by the commit SHA1 and since SHA1 does such a good job of distributing values around we get pretty even distribution among the buckets. This gets us a 1/256 reduction within each bucket, at the cost of just one array index operation.

Since the buckets are so small (1 pointer) and the match function is in the critical path of describe it would seem reasonable to take the small memory hit in return for better behavior on very large sets of tags. It certainly doesn't hurt on smaller tag sets (like git.git), we wind up with 1 tag per bucket and our lookups are constant time.

-- 
Shawn.
Previous: Junio C HamanoNext: Shawn O. Pearce
Message 7 of 8 in “Hash tags by commit SHA1 in git-describe.”
  1. 2/4 Hash tags by commit SHA1 in git-describe.Shawn O. Pearce, Jan 13, 2007
  2. Johannes SchindelinJan 14, 2007
  3. Junio C HamanoJan 14, 2007
  4. Shawn O. PearceJan 14, 2007
  5. 3/4 Use binary searching on large buckets in git-describe.Shawn O. Pearce, Jan 13, 2007
  6. Junio C HamanoJan 14, 2007
  7. Shawn O. PearceJan 14, 2007
  8. 4/4 Improve git-describe performance by reducing revision listing.Shawn O. Pearce, Jan 13, 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.