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

Re: [PATCH] sha1_name: use bsearch_hash() for abbreviations

From
Derrick Stolee <stolee@gmail.com>
Date
Mar 21, 2018, 13:24 UTC
Message-ID
<3527bd3a-a899-a909-5fda-1d7abeb0e158@gmail.com>
In-Reply-To
<20180320152505.bd66f0deaecf6d92fa6d62de@google.com>
On 3/20/2018 6:25 PM, Jonathan Tan wrote:
Show 13 quoted lines
> On Tue, 20 Mar 2018 16:03:25 -0400
> Derrick Stolee <dstolee@microsoft.com> wrote:
>
>> This patch updates the abbreviation code to use bsearch_hash() as defined
>> in [1]. It gets a nice speedup since the old implementation did not use
>> the fanout table at all.
> You can refer to the patch as:
>
>    b4e00f7306a1 ("packfile: refactor hash search with fanout table",
>    2018-02-15)
>
> Also, might be worth noting that this patch builds on
> jt/binsearch-with-fanout.

Thanks. That commit is in master and v2.17.0-rc0, so hopefully it isn't difficult to apply the patch.

Show 9 quoted lines
>
>> One caveat about the patch: there is a place where I cast a sha1 hash
>> into a struct object_id pointer. This is because the abbreviation code
>> still uses 'const unsigned char *' instead of structs. I wanted to avoid
>> a hashcpy() in these calls, but perhaps that is not too heavy a cost.
> I recall a discussion that there were alignment issues with doing this,
> but I might have be remembering wrongly - in my limited knowledge of C
> alignment, both "unsigned char *" and "struct object_id *" have the same
> constraints, but I'm not sure.

Adding Brian M. Carlson in the CC line for advice on how to do this translation between old sha1's and new object_ids. If it isn't safe, then we could do a hashcpy() until the translation makes it unnecessary.

I should have compared the two methods before sending the patch, but running the "git log --oneline --parents" test with a hashcpy() versus a cast has no measurable difference in performance for Linux. Probably best to do the safest thing here if there is no cost to perf.

Show 9 quoted lines
>
>> +	const unsigned char *index_fanout = p->index_data;
> [snip]
>> +	return bsearch_hash(oid->hash, (const uint32_t*)index_fanout,
>> +			    index_lookup, index_lookup_width, result);
> This cast to "const uint32_t *" is safe, because p->index_data points to
> a mmap-ed region (which has very good alignment, as far as I know). I
> wonder if we should document alignment guarantees on p->index_data, and
> if yes, what guarantees to declare.

The existing application in find_pack_entry_one() [1] does similar pack-index arithmetic before calling. A similar amount of arithmetic and alignment concerns appear in the commit-graph patch. Where is the right place to declare these alignment requirements?

In v2, I'll have find_pack_entry_one() call bsearch_pack() so this logic is not duplicated.

Thanks, -Stolee

[1] 
https://github.com/git/git/blob/c6284da4ff4afbde8211efe5d03f3604b1c6b9d6/packfile.c#L1721-L1749
     find_pack_entry_one() in packfile.c
Previous: Jonathan TanNext: brian m. carlson
Message 3 of 12 in “sha1_name: use bsearch_hash() for abbreviations”
  1. sha1_name: use bsearch_hash() for abbreviationsDerrick Stolee, Mar 20, 2018
  2. Jonathan TanMar 20, 2018
  3. Derrick StoleeMar 21, 2018
  4. brian m. carlsonMar 21, 2018
  5. 0/3 Use bsearch_hash() for abbreviationsDerrick Stolee, Mar 22, 2018
  6. 2/3 packfile: define and use bsearch_pack()Derrick Stolee, Mar 22, 2018
  7. 1/3 sha1_name: convert struct min_abbrev_data to object_idDerrick Stolee, Mar 22, 2018
  8. 3/3 sha1_name: use bsearch_pack() for abbreviationsDerrick Stolee, Mar 22, 2018
  9. 4/3 sha1_name: use bsearch_pack() in unique_in_pack()René Scharfe, Mar 24, 2018
  10. Junio C HamanoMar 25, 2018
  11. René ScharfeMar 25, 2018
  12. Derrick StoleeMar 25, 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.