@matheusbsbs / matheus-bagliano / commits / c82d7117a1
Fork 0

Improve merge performance by avoiding in-index merges.

In the early days of Git we performed a 3-way read-tree based merge before attempting any specific merge strategy, as our core merge strategies of merge-one-file and merge-recursive were slower script based programs which took far longer to execute. This was a good performance optimization in the past, as most merges were able to be handled strictly by `read-tree -m -u`. However now that merge-recursive is a C based program which performs a full 3-way read-tree before it starts running we need to pay the cost of the 3-way read-tree twice if we have to do any sort of file level merging. This slows down some classes of simple merges which `read-tree -m -u` could not handle but which merge-recursive does automatically. For a really trivial merge which can be handled entirely by `read-tree -m -u`, skipping the read-tree and just going directly into merge-recursive saves on average 50 ms on my PowerPC G4 system. May sound odd, but it does appear to be true. In a really simple merge which needs to use merge-recursive to handle a file that was modified on both branches, skipping the read-tree in git-merge saves on average almost 100 ms (on the same PowerPC G4) as we avoid doing some work twice. We only avoid `read-tree -m -u` if the only strategy to use is merge-recursive, as not all merge strategies perform as well as merge-recursive does. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Dec 28, 2006 at 02:35 UTC c82d7117a1f499b43e21e0a4589a080edadaf706
1 file changed +23 -17
git-merge.sh
+23 -17
@@ -298,24 +298,30 @@ f,*)
298 ;;
299 ?,1,*,)
300 # We are not doing octopus, not fast forward, and have only
301 - # one common. See if it is really trivial.
302 - git var GIT_COMMITTER_IDENT >/dev/null || exit
303 -
304 - echo "Trying really trivial in-index merge..."
301 + # one common.
302 git-update-index --refresh 2>/dev/null
306 - if git-read-tree --trivial -m -u -v $common $head "$1" &&
307 - result_tree=$(git-write-tree)
308 - then
309 - echo "Wonderful."
310 - result_commit=$(
311 - echo "$merge_msg" |
312 - git-commit-tree $result_tree -p HEAD -p "$1"
313 - ) || exit
314 - finish "$result_commit" "In-index merge"
315 - dropsave
316 - exit 0
317 - fi
318 - echo "Nope."
303 + case " $use_strategies " in
304 + *' recursive '*|*' recur '*)
305 + : run merge later
306 + ;;
307 + *)
308 + # See if it is really trivial.
309 + git var GIT_COMMITTER_IDENT >/dev/null || exit
310 + echo "Trying really trivial in-index merge..."
311 + if git-read-tree --trivial -m -u -v $common $head "$1" &&
312 + result_tree=$(git-write-tree)
313 + then
314 + echo "Wonderful."
315 + result_commit=$(
316 + echo "$merge_msg" |
317 + git-commit-tree $result_tree -p HEAD -p "$1"
318 + ) || exit
319 + finish "$result_commit" "In-index merge"
320 + dropsave
321 + exit 0
322 + fi
323 + echo "Nope."
324 + esac
325 ;;
326 *)
327 # An octopus. If we can reach all the remote we are up to date.