Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] merge: optimization to skip evaluate_result for single strategy
@ 2020-05-18 15:36 anng.sw
  2020-05-18 17:23 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: anng.sw @ 2020-05-18 15:36 UTC (permalink / raw)
  To: git; +Cc: gitster, eantoranz, Andrew Ng

From: Andrew Ng <andrew.ng@sony.com>

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.

Signed-off-by: Andrew Ng <andrew.ng@sony.com>
---
 builtin/merge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index ca6a5dc4bf..7da707bf55 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -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;
-- 
2.26.2.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] merge: optimization to skip evaluate_result for single strategy
  2020-05-18 15:36 [PATCH] merge: optimization to skip evaluate_result for single strategy anng.sw
@ 2020-05-18 17:23 ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2020-05-18 17:23 UTC (permalink / raw)
  To: anng.sw; +Cc: git, eantoranz, Andrew Ng

anng.sw@gmail.com writes:

> From: Andrew Ng <andrew.ng@sony.com>
>
> 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.

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

s/half/halve/

> recursive merge of a single commit with the LLVM repo.
>
> Signed-off-by: Andrew Ng <andrew.ng@sony.com>
> ---
>  builtin/merge.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/merge.c b/builtin/merge.c
> index ca6a5dc4bf..7da707bf55 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -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.

>  			if (best_cnt <= 0 || cnt <= best_cnt) {
>  				best_strategy = use_strategies[i]->name;
>  				best_cnt = cnt;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] merge: optimization to skip evaluate_result for single strategy
@ 2020-05-19 13:05 anng.sw
  0 siblings, 0 replies; 3+ messages in thread
From: anng.sw @ 2020-05-19 13:05 UTC (permalink / raw)
  To: gitster; +Cc: git, Andrew Ng

From: Andrew Ng <andrew.ng@sony.com>

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 halve the time required to perform a
recursive merge of a single commit with the LLVM repo.

Signed-off-by: Andrew Ng <andrew.ng@sony.com>
Reviewed-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/merge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index ca6a5dc4bf..7da707bf55 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -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;
-- 
2.26.2.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-18 15:36 [PATCH] merge: optimization to skip evaluate_result for single strategy anng.sw
2020-05-18 17:23 ` Junio C Hamano
2020-05-19 13:05 anng.sw

Git Mailing List Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/git/0 git/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 git git/ https://lore.kernel.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.git


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git