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

Re: [PATCH 2/2] packfile: refactor hash search with fanout table

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Feb 9, 2018, 19:50 UTC
Message-ID
<20180209115051.b9356543f3f7d07f3bae213f@google.com>
In-Reply-To
<cfbde137-dbac-8796-f49f-2a543303d33a@web.de>

On Fri, 9 Feb 2018 19:03:48 +0100 René Scharfe <l.s.r@web.de> wrote:

> Going from unsigned to signed int means the patch breaks support for
> more than 2G pack entries, which was put with 326bf39677 (Use uint32_t
> for all packed object counts.) in 2007.

Ah, good catch. I'll wait to see if there are any more comments, then send out a new version.

Show 6 quoted lines
> > +int bsearch_hash(const unsigned char *sha1, const void *fanout_,
> > +		 const void *table_, size_t stride)
> > +{
> > +	const uint32_t *fanout = fanout_;
> 
> Why hide the type?  It doesn't make the function more generic.
I thought that the fanout_ parameter could come from a variety of
sources (e.g. direct mmap - void *, or mmap with some pointer arithmetic
- char *) so I just picked the generic one. But now I realize that that
could lead to unaligned reads, which is probably not a good idea. I'll
update it.

For consistency, I'll also update table_ to be unsigned char *. (Unsigned because it is primarily interpreted as hashes, which use "unsigned char *" in the Git code.)

> Why not use sha1_pos()?  I guess because it avoids the overhead of the
> accessor function, right?  And I wonder how much of difference it makes.

Yes, overhead of the accessor function. We would also need to modify sha1_pos to take in a function that we can pass userdata to (to contain the stride).

> A binary search function for embedded hashes just needs the key, a
> pointer to the first hash in the array, the stride and the number of
> elements.  It can then be used with or without a fanout table, making it
> more versatile.  Just a thought.

I specifically want to include the fanout table in the calculation here, because it will be used by subsequent patches that also incorporate the fanout table.

Previous: René ScharfeNext: Junio C Hamano
Message 5 of 13 in “Refactor hash search with fanout table”
  1. 0/2 Refactor hash search with fanout tableJonathan Tan, Feb 2, 2018
  2. 1/2 packfile: remove GIT_DEBUG_LOOKUP log statementsJonathan Tan, Feb 2, 2018
  3. 2/2 packfile: refactor hash search with fanout tableJonathan Tan, Feb 2, 2018
  4. René ScharfeFeb 9, 2018
  5. Jonathan TanFeb 9, 2018
  6. Junio C HamanoFeb 2, 2018
  7. Derrick StoleeFeb 3, 2018
  8. 0/2 Refactor hash search with fanout tableJonathan Tan, Feb 13, 2018
  9. 2/2 packfile: refactor hash search with fanout tableJonathan Tan, Feb 13, 2018
  10. 1/2 packfile: remove GIT_DEBUG_LOOKUP log statementsJonathan Tan, Feb 13, 2018
  11. Derrick StoleeFeb 13, 2018
  12. Junio C HamanoFeb 13, 2018
  13. Jonathan TanFeb 13, 2018

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.