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

[PATCH v11 3/5] read-cache: speed up add_index_entry during checkout

From
Ggit@jeffhostetler.com <git@jeffhostetler.com>
Date
Apr 17, 2017, 21:37 UTC
Message-ID
<20170417213734.55373-4-git@jeffhostetler.com>
In-Reply-To
<20170417213734.55373-1-git@jeffhostetler.com>
From: Jeff Hostetler <jeffhost@microsoft.com>

Teach add_index_entry_with_check() to see if the path of the new item is greater than the last path in the index array before attempting to search for it.

During checkout, merge_working_tree() populates the new index in sorted order, so this change will save a binary lookups per file. This preserves the original behavior but simply checks the last element before starting the search.

This helps performance on very large repositories.
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 read-cache.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/read-cache.c b/read-cache.c
index 97f13a1..6a27688 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1021,7 +1021,16 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
 
 	if (!(option & ADD_CACHE_KEEP_CACHE_TREE))
 		cache_tree_invalidate_path(istate, ce->name);
-	pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
+
+	/*
+	 * If this entry's path sorts after the last entry in the index,
+	 * we can avoid searching for it.
+	 */
+	if (istate->cache_nr > 0 &&
+		strcmp(ce->name, istate->cache[istate->cache_nr - 1]->name) > 0)
+		pos = -istate->cache_nr - 1;
+	else
+		pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
 
 	/* existing match? Just replace it. */
 	if (pos >= 0) {
-- 
2.9.3
Previous: git@jeffhostetler.comNext: git@jeffhostetler.com
Message 3 of 8 in “read-cache: speed up add_index_entry”
  1. 0/5 read-cache: speed up add_index_entrygit@jeffhostetler.com, Apr 17, 2017
  2. 1/5 read-cache: add strcmp_offset functiongit@jeffhostetler.com, Apr 17, 2017
  3. 3/5 read-cache: speed up add_index_entry during checkoutgit@jeffhostetler.com, Apr 17, 2017
  4. 2/5 p0006-read-tree-checkout: perf test to time read-treegit@jeffhostetler.com, Apr 17, 2017
  5. Thomas GummererApr 18, 2017
  6. Jeff KingApr 19, 2017
  7. 4/5 read-cache: speed up has_dir_name (part 1)git@jeffhostetler.com, Apr 17, 2017
  8. 5/5 read-cache: speed up has_dir_name (part 2)git@jeffhostetler.com, Apr 17, 2017

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.