Skip to contentSkip to conversation

diff: try lazy read of config only once

PATCH In review Jeff King 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore

Jeff King

author
#0 lore raw

PATCH 1/1 diff: try lazy read of config only once

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.

---
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.c +5 -0
index 5bdc111..f6a8515 100644
@@ -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;
 }
 
 /*
Signature · 1 line
1.5.4.rc2.1122.g6954-dirty
#1 lore raw

Thanks. I think you can lose "if (!user_diff_tail)" there as well.

author
#2 lore raw
Quoted 2 lines · Junio C Hamano

Thanks. I think you can lose "if (!user_diff_tail)" there as well.

Oops, yes. Please mark it up when you apply.

-Peff