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

[PATCH] diff: try lazy read of config only once

From
Jeff King <peff@peff.net>
Date
Jan 4, 2008, 08:31 UTC
Message-ID
<20080104083116.GA3354@coredump.intra.peff.net>

The function read_config_if_needed used a list pointer to determined whether it had already been called. However, if the user had no diff drivers, the function would repeatedly read the config (typically once per diffed file).

Instead, let's use a signal variable so that we read it only once (note that we may actually still read it an extra time, since the config may already have been read outside of this function). This reduces the cost of

  git-whatchanged -p >/dev/null
from 34 seconds to 33 seconds.
Signed-off-by: Jeff King <peff@peff.net>
---
This are might be changed from the fallout of the other mail I just
sent, but I wanted to at least mention it. The speedup is not terribly
significant, but it just seems stupid to parse the config file thousands
of times. And I suspect on slow-I/O systems (like Cygwin) that it might
make more of a difference.
 diff.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/diff.c b/diff.c
index 5bdc111..f6a8515 100644
--- a/diff.c
+++ b/diff.c
@@ -61,10 +61,15 @@ static struct ll_diff_driver {
 
 static void read_config_if_needed(void)
 {
+	static int done = 0;
+	if (done)
+		return;
+
 	if (!user_diff_tail) {
 		user_diff_tail = &user_diff;
 		git_config(git_diff_ui_config);
 	}
+	done = 1;
 }
 
 /*
-- 
1.5.4.rc2.1122.g6954-dirty
Next: Junio C Hamano
Message 1 of 3 in “diff: try lazy read of config only once”
  1. diff: try lazy read of config only onceJeff King, Jan 4, 2008
  2. Junio C HamanoJan 4, 2008
  3. Jeff KingJan 4, 2008

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.