{"thread":{"id":"53496","subject":"[PATCH] merge: optimization to skip evaluate_result for single strategy","startedAt":"2020-05-18T15:36:43Z","lastAt":"2020-05-18T17:23:42Z","messageCount":2,"participants":["anng.sw@gmail.com","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"398077","messageId":"20200518153613.17497-1-anng.sw@gmail.com","threadId":"53496","inReplyTo":null,"subject":"[PATCH] merge: optimization to skip evaluate_result for single strategy","fromName":"","fromEmail":"anng.sw@gmail.com","sentAt":"2020-05-18T15:36:13Z","receivedAt":"2020-05-18T15:36:43Z","isPatch":true,"sender":{"key":"anng.sw@gmail.com","avatar":null},"body":"From: Andrew Ng <andrew.ng@sony.com>\n\nFor a merge with a single strategy, the result of evaluate_result() is\neffectively not used and therefore is not needed, so avoid altogether.\n\nOn Windows, this optimization can half the time required to perform a\nrecursive merge of a single commit with the LLVM repo.\n\nSigned-off-by: Andrew Ng <andrew.ng@sony.com>\n---\n builtin/merge.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex ca6a5dc4bf..7da707bf55 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1656,7 +1656,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\t\t}\n \t\t\t\tmerge_was_ok = 1;\n \t\t\t}\n-\t\t\tcnt = evaluate_result();\n+\t\t\tcnt = (use_strategies_nr > 1) ? evaluate_result() : 0;\n \t\t\tif (best_cnt <= 0 || cnt <= best_cnt) {\n \t\t\t\tbest_strategy = use_strategies[i]->name;\n \t\t\t\tbest_cnt = cnt;\n-- \n2.26.2.windows.1\n\n"},{"id":"398107","messageId":"xmqqk11940o9.fsf@gitster.c.googlers.com","threadId":"53496","inReplyTo":"20200518153613.17497-1-anng.sw@gmail.com","subject":"Re: [PATCH] merge: optimization to skip evaluate_result for single strategy","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-18T17:23:34Z","receivedAt":"2020-05-18T17:23:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"anng.sw@gmail.com writes:\n\n> From: Andrew Ng <andrew.ng@sony.com>\n>\n> For a merge with a single strategy, the result of evaluate_result() is\n> effectively not used and therefore is not needed, so avoid altogether.\n\nExcellent observation.\n\n> On Windows, this optimization can half the time required to perform a\n\ns/half/halve/\n\n> recursive merge of a single commit with the LLVM repo.\n>\n> Signed-off-by: Andrew Ng <andrew.ng@sony.com>\n> ---\n>  builtin/merge.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/builtin/merge.c b/builtin/merge.c\n> index ca6a5dc4bf..7da707bf55 100644\n> --- a/builtin/merge.c\n> +++ b/builtin/merge.c\n> @@ -1656,7 +1656,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n>  \t\t\t\t}\n>  \t\t\t\tmerge_was_ok = 1;\n>  \t\t\t}\n> -\t\t\tcnt = evaluate_result();\n> +\t\t\tcnt = (use_strategies_nr > 1) ? evaluate_result() : 0;\n\nAs best_cnt is initialized to (-1), any value would trigger the\nlogic to nominate the current one as \"best so far\", and 0 is just as\ngood as it gets ;-)  And we'll finish the loop soon after doing so.\n\nLooks good.\n\n>  \t\t\tif (best_cnt <= 0 || cnt <= best_cnt) {\n>  \t\t\t\tbest_strategy = use_strategies[i]->name;\n>  \t\t\t\tbest_cnt = cnt;\n\n"}]}