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

[PATCH] defer expensive load_ref_decorations until needed

From
Phil Hord <phil.hord@gmail.com>
Date
Nov 21, 2017, 23:43 UTC
Message-ID
<20171121234336.10209-1-phil.hord@gmail.com>

With many thousands of references, a simple `git rev-parse HEAD` may take more than a second to return because it first loads all the refs into memory even though it will never use them.

Defer loading any references until we actually need them.
Signed-off-by: Phil Hord <phil.hord@gmail.com>
---
 log-tree.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index 3b904f037..c1509f8b9 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -84,8 +84,10 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj
 	res->next = add_decoration(&name_decoration, obj, res);
 }
 
+static void maybe_load_ref_decorations();
 const struct name_decoration *get_name_decoration(const struct object *obj)
 {
+	maybe_load_ref_decorations();
 	return lookup_decoration(&name_decoration, obj);
 }
 
@@ -150,10 +152,13 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
 
 void load_ref_decorations(int flags)
 {
-	if (!decoration_loaded) {
+	decoration_flags = flags;
+}
 
+static void maybe_load_ref_decorations()
+{
+	if (!decoration_loaded) {
 		decoration_loaded = 1;
-		decoration_flags = flags;
 		for_each_ref(add_ref_decoration, NULL);
 		head_ref(add_ref_decoration, NULL);
 		for_each_commit_graft(add_graft_decoration, NULL);
-- 
2.15.0.471.g17a719cfe.dirty
Next: Junio C Hamano
Message 1 of 9 in “defer expensive load_ref_decorations until needed”
  1. defer expensive load_ref_decorations until neededPhil Hord, Nov 21, 2017
  2. Junio C HamanoNov 22, 2017
  3. Junio C HamanoNov 22, 2017
  4. Phil HordNov 22, 2017
  5. Jeff KingNov 22, 2017
  6. Phil HordNov 22, 2017
  7. Jeff KingNov 22, 2017
  8. Junio C HamanoNov 23, 2017
  9. Jeff KingNov 23, 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.