{"thread":{"id":"11465","subject":"[PATCH] diff: try lazy read of config only once","startedAt":"2008-01-04T08:31:16Z","lastAt":"2008-01-04T08:40:24Z","messageCount":3,"participants":["Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64419","messageId":"20080104083116.GA3354@coredump.intra.peff.net","threadId":"11465","inReplyTo":null,"subject":"[PATCH] diff: try lazy read of config only once","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-04T08:31:16Z","receivedAt":"2008-01-04T08:31:16Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The function read_config_if_needed used a list pointer to\ndetermined whether it had already been called. However, if\nthe user had no diff drivers, the function would repeatedly\nread the config (typically once per diffed file).\n\nInstead, let's use a signal variable so that we read it only\nonce (note that we may actually still read it an extra time,\nsince the config may already have been read outside of this\nfunction). This reduces the cost of\n\n  git-whatchanged -p >/dev/null\n\nfrom 34 seconds to 33 seconds.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis are might be changed from the fallout of the other mail I just\nsent, but I wanted to at least mention it. The speedup is not terribly\nsignificant, but it just seems stupid to parse the config file thousands\nof times. And I suspect on slow-I/O systems (like Cygwin) that it might\nmake more of a difference.\n\n diff.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 5bdc111..f6a8515 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -61,10 +61,15 @@ static struct ll_diff_driver {\n \n static void read_config_if_needed(void)\n {\n+\tstatic int done = 0;\n+\tif (done)\n+\t\treturn;\n+\n \tif (!user_diff_tail) {\n \t\tuser_diff_tail = &user_diff;\n \t\tgit_config(git_diff_ui_config);\n \t}\n+\tdone = 1;\n }\n \n /*\n-- \n1.5.4.rc2.1122.g6954-dirty\n"},{"id":"64423","messageId":"7v1w8ym1g6.fsf@gitster.siamese.dyndns.org","threadId":"11465","inReplyTo":"20080104083116.GA3354@coredump.intra.peff.net","subject":"Re: [PATCH] diff: try lazy read of config only once","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-04T08:36:57Z","receivedAt":"2008-01-04T08:36:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.  I think you can lose \"if (!user_diff_tail)\" there as\nwell.\n"},{"id":"64424","messageId":"20080104084024.GA3522@coredump.intra.peff.net","threadId":"11465","inReplyTo":"7v1w8ym1g6.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] diff: try lazy read of config only once","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-04T08:40:24Z","receivedAt":"2008-01-04T08:40:24Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Jan 04, 2008 at 12:36:57AM -0800, Junio C Hamano wrote:\n\n> Thanks.  I think you can lose \"if (!user_diff_tail)\" there as\n> well.\n\nOops, yes. Please mark it up when you apply.\n\n-Peff\n"}]}