Skip to contentSkip to conversation

merge: optimization to skip evaluate_result for single strategy

PATCH In review [email protected] 2 participants 2 messages May 18, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 merge: optimization to skip evaluate_result for single strategy

From: Andrew Ng <[email protected]>

For a merge with a single strategy, the result of evaluate_result() is effectively not used and therefore is not needed, so avoid altogether.

On Windows, this optimization can half the time required to perform a recursive merge of a single commit with the LLVM repo.

---
 builtin/merge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/merge.c +1 -1
index ca6a5dc4bf..7da707bf55 100644
@@ -1656,7 +1656,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 				}
 				merge_was_ok = 1;
 			}
-			cnt = evaluate_result();
+			cnt = (use_strategies_nr > 1) ? evaluate_result() : 0;
 			if (best_cnt <= 0 || cnt <= best_cnt) {
 				best_strategy = use_strategies[i]->name;
 				best_cnt = cnt;
Signature · 1 line
2.26.2.windows.1
#1 lore raw
Quoted 4 lines · [email protected] writes:

From: Andrew Ng <[email protected]>

For a merge with a single strategy, the result of evaluate_result() is effectively not used and therefore is not needed, so avoid altogether.

Excellent observation.

Quoted 1 line

On Windows, this optimization can half the time required to perform a

s/half/halve/

Quoted 12 lines

recursive merge of a single commit with the LLVM repo.

---
 builtin/merge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/merge.c +0 -0
index ca6a5dc4bf..7da707bf55 100644

builtin/merge.c int cmd_merge(int argc, const char **argv, const char *prefix) · line 1659

Quoted 5 lines
builtin/merge.c +1 -1
@@ -1656,7 +1656,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 				}
 				merge_was_ok = 1;
 			}
-			cnt = evaluate_result();
+			cnt = (use_strategies_nr > 1) ? evaluate_result() : 0;

As best_cnt is initialized to (-1), any value would trigger the logic to nominate the current one as "best so far", and 0 is just as good as it gets ;-) And we'll finish the loop soon after doing so.

Looks good.

Quoted 3 lines
builtin/merge.c +0 -0
 			if (best_cnt <= 0 || cnt <= best_cnt) {
 				best_strategy = use_strategies[i]->name;
 				best_cnt = cnt;