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

[PATCH v2 3/3] sha1_name: use bsearch_pack() for abbreviations

From
Derrick Stolee <dstolee@microsoft.com>
Date
Mar 22, 2018, 17:40 UTC
Message-ID
<20180322174010.120117-4-dstolee@microsoft.com>
In-Reply-To
<20180322174010.120117-1-dstolee@microsoft.com>

When computing abbreviation lengths for an object ID against a single packfile, the method find_abbrev_len_for_pack() currently implements binary search. This is one of several implementations. One issue with this implementation is that it ignores the fanout table in the pack- index.

Translate this binary search to use the existing bsearch_pack() method that correctly uses a fanout table.

Due to the use of the fanout table, the abbreviation computation is slightly faster than before. For a fully-repacked copy of the Linux repo, the following 'git log' commands improved:

* git log --oneline --parents --raw
  Before: 59.2s
  After:  56.9s
  Rel %:  -3.8%
* git log --oneline --parents
  Before: 6.48s
  After:  5.91s
  Rel %: -8.9%
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 sha1_name.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 16e0003396..24894b3dbe 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -512,32 +512,16 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
 				     struct min_abbrev_data *mad)
 {
 	int match = 0;
-	uint32_t num, last, first = 0;
+	uint32_t num, first = 0;
 	struct object_id oid;
+	const struct object_id *mad_oid;
 
 	if (open_pack_index(p) || !p->num_objects)
 		return;
 
 	num = p->num_objects;
-	last = num;
-	while (first < last) {
-		uint32_t mid = first + (last - first) / 2;
-		const unsigned char *current;
-		int cmp;
-
-		current = nth_packed_object_sha1(p, mid);
-		cmp = hashcmp(mad->oid->hash, current);
-		if (!cmp) {
-			match = 1;
-			first = mid;
-			break;
-		}
-		if (cmp > 0) {
-			first = mid + 1;
-			continue;
-		}
-		last = mid;
-	}
+	mad_oid = mad->oid;
+	match = bsearch_pack(mad_oid, p, &first);
 
 	/*
 	 * first is now the position in the packfile where we would insert
-- 
2.17.0.rc0
Previous: Derrick StoleeNext: René Scharfe
Message 8 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.