Patrick Steinhardt reported that 'git log --stat --follow -- include/linux/rsc_table.h' in linux.git took roughly 33 seconds with Git 2.55 and almost 8 minutes with Git 2.56. He bisected it to 304812ed33 (log: improve --follow following renames for non-linear history).

Miklos Vajna, the author of that commit, traced the cause. log_tree_diff() diffs each merge against all of its parents with rename following. diff_tree_oid() only does the expensive rename detection when the path is added relative to a parent, and that is common for merges. One example is a branch forked before the path existed that later merges mainline.

In v5, per his cover letter, the fix for a 'git log -m --follow' problem in the t4219 diamond case is squashed into the speedup patch (5/5), so no commit in the series loses history. The speedup first looks for a parent where the path is unchanged. It diffs against the other parents only if they still need renames followed.

Patrick Steinhardt raised two cases in review of v4. The first is file copying: the pre-filter now also considers a file the merge still has but with the other side's version, and the rename check now detects copies. Miklos says this makes the linux.git case take about 42 seconds, against 37 seconds before.

The second is a merge where a parent has no merge base with the parent that keeps the path unchanged, such as a subtree merge of unrelated histories. follow_needs_renames() now returns 1 when there is no merge base, so renames are followed as before. A new test, '--follow finds the history of a copied file through a subtree merge', was added to patch 1/5.

The series is now five patches, and it is not yet clear whether v5 settles the review.