threads / rfc / 51666

RFC patch, 5 partsline-log: towards a more responsive, incremental 'git log -L'

Subject: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

## tl;dr

17 messages between Aug 18, 2019 and Apr 24, 2020. Diffs are folded; open one to read it.

replies: 16people: 2as markdown or json

SZEDER Gábor· Aug 18, 2019, 18:27 UTC · lore

Line-level log performs a preprocessing step in prepare_revision_walk(), during which it filters and rewrites history to keep only commits modifying the given line range. This preprocessing causes significant delay before the first commit is shown, wastes CPU time when the user asks only for a few commits, and does parent rewriting with no way to turn it off.

This patch series addresses these issues by integrating line-level log filtering into the revision walking machinery and making it work together with generation number-based topo-ordering (though for now only in the case when the user doesn't explicitly asks for parent rewriting, which is probably the common case).

The first two patches are quite straightforward (and arguably somewhat unrelated), but the rest deals with history traversal and parent rewriting, which I don't usually do, hence the RFC.

SZEDER Gábor (5):
  completion: offer '--(no-)patch' among 'git log' options
  line-log: remove unused fields from 'struct line_log_data'
  t4211-line-log: add tests for parent oids
  line-log: more responsive, incremental 'git log -L'
  line-log: try to use generation number-based topo-ordering
 contrib/completion/git-completion.bash |  1 +
 line-log.c                             |  4 +-
 line-log.h                             |  5 +-
 revision.c                             | 38 +++++++++++---
 t/t4211-line-log.sh                    | 68 ++++++++++++++++++++++++++
 5 files changed, 105 insertions(+), 11 deletions(-)
-- 
2.23.0.349.g73f10e387d
SZEDER Gábor· Aug 18, 2019, 18:27 UTC · re: SZEDER Gábor · lore

[RFC PATCH 1/5] completion: offer '--(no-)patch' among 'git log' options

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 contrib/completion/git-completion.bash | 1 +
 1 file changed, 1 insertion(+)
Show changes to contrib/completion/git-completion.bash +1 −0
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e087c4bf00..57f984340e 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1804,6 +1804,7 @@ _git_log ()
 			$merge
 			$__git_diff_common_options
 			--pickaxe-all --pickaxe-regex
+			--patch --no-patch
 			"
 		return
 		;;
-- 
2.23.0.349.g73f10e387d
SZEDER Gábor· Aug 18, 2019, 18:27 UTC · re: SZEDER Gábor · lore

[RFC PATCH 2/5] line-log: remove unused fields from 'struct line_log_data'

Remove the unused fields 'status', 'arg_alloc', 'arg_nr' and 'args' from 'struct line_log_data'. They were already part of the struct when it was introduced in commit 12da1d1f6 (Implement line-history search (git log -L), 2013-03-28), but as far as I can tell none of them have ever been actually used.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 line-log.h | 3 ---
 1 file changed, 3 deletions(-)
Show changes to line-log.h +0 −3
diff --git a/line-log.h b/line-log.h
index 8ee7a2bd4a..882c5055bb 100644
--- a/line-log.h
+++ b/line-log.h
@@ -46,10 +46,7 @@ void sort_and_merge_range_set(struct range_set *);
 struct line_log_data {
 	struct line_log_data *next;
 	char *path;
-	char status;
 	struct range_set ranges;
-	int arg_alloc, arg_nr;
-	const char **args;
 	struct diff_filepair *pair;
 	struct diff_ranges diff;
 };
-- 
2.23.0.349.g73f10e387d
Derrick Stolee· Aug 19, 2019, 11:53 UTC · re: SZEDER Gábor · lore

Re: [RFC PATCH 2/5] line-log: remove unused fields from 'struct line_log_data'

On 8/18/2019 2:27 PM, SZEDER Gábor wrote:
Show 5 quoted lines
> Remove the unused fields 'status', 'arg_alloc', 'arg_nr' and 'args'
> from 'struct line_log_data'.  They were already part of the struct
> when it was introduced in commit 12da1d1f6 (Implement line-history
> search (git log -L), 2013-03-28), but as far as I can tell none of
> them have ever been actually used.
Good cleanup! 
-Stolee
SZEDER Gábor· Aug 18, 2019, 18:27 UTC · re: SZEDER Gábor · lore

[RFC PATCH 3/5] t4211-line-log: add tests for parent oids

None of the tests in 't4211-line-log.sh' really check which parent object IDs are shown in the output, either implicitly as part of "Merge: ..." lines [1] or explicitly via the '%p' or '%P' format specifiers in a custom pretty format.

Add two tests to 't4211-line-log.sh' to check which parent object IDs are shown, one without and one with explicitly requested parent rewriting, IOW without and with the '--parents' option.

The test without '--parents' is marked as failing, because without that option parent rewriting should not be performed, and thus the parent object ID should be that of the immediate parent, just like in case of a pathspec-limited history traversal without parent rewriting. The current line-level log implementation, however, performs parent rewriting unconditionally and without a possibility to turn it off, and, consequently, it shows the object ID of the most recent ancestor that modified the given line range.

In both of these new tests we only really care about the object IDs of the listed commits and their parents, but not the diffs of the line ranges; the diffs have already been thoroughly checked in the previous tests.

[1] While one of the tests ('-M -L ':f:b.c' parallel-change') does
    list a merge commit, both of its parents happen to modify the
    given line range and are listed as well, so the implications of
    parent rewriting remained hidden and untested.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 t/t4211-line-log.sh | 68 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
Show changes to t/t4211-line-log.sh +68 −0
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index 1db7bd0f59..c378a453de 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -132,4 +132,72 @@ test_expect_success '--raw is forbidden' '
 	test_must_fail git log -L1,24:b.c --raw
 '
 
+# Create the following linear history, where each commit does what its
+# subject line promises:
+#
+#   * 66c6410 Modify func2() in file.c
+#   * 50834e5 Modify other-file
+#   * fe5851c Modify func1() in file.c
+#   * 8c7c7dd Add other-file
+#   * d5f4417 Add func1() and func2() in file.c
+test_expect_success 'setup for checking line-log and parent oids' '
+	git checkout --orphan parent-oids &&
+	git reset --hard &&
+
+	cat >file.c <<-\EOF &&
+	int func1()
+	{
+	    return F1;
+	}
+
+	int func2()
+	{
+	    return F2;
+	}
+	EOF
+	git add file.c &&
+	test_tick &&
+	git commit -m "Add func1() and func2() in file.c" &&
+
+	echo 1 >other-file &&
+	git add other-file &&
+	git commit -m "Add other-file" &&
+
+	sed -e "s/F1/F1 + 1/" file.c >tmp &&
+	mv tmp file.c &&
+	git commit -a -m "Modify func1() in file.c" &&
+
+	echo 2 >other-file &&
+	git commit -a -m "Modify other-file" &&
+
+	sed -e "s/F2/F2 + 2/" file.c >tmp &&
+	mv tmp file.c &&
+	git commit -a -m "Modify func2() in file.c" &&
+
+	head_oid=$(git rev-parse --short HEAD) &&
+	prev_oid=$(git rev-parse --short HEAD^) &&
+	root_oid=$(git rev-parse --short HEAD~4)
+'
+
+# Parent oid should be from immediate parent.
+test_expect_failure 'parent oids without parent rewriting' '
+	cat >expect <<-EOF &&
+	$head_oid $prev_oid Modify func2() in file.c
+	$root_oid  Add func1() and func2() in file.c
+	EOF
+	git log --format="%h %p %s" --no-patch -L:func2:file.c >actual &&
+	test_cmp expect actual
+'
+
+# Parent oid should be from the most recent ancestor touching func2(),
+# i.e. in this case from the root commit.
+test_expect_success 'parent oids with parent rewriting' '
+	cat >expect <<-EOF &&
+	$head_oid $root_oid Modify func2() in file.c
+	$root_oid  Add func1() and func2() in file.c
+	EOF
+	git log --format="%h %p %s" --no-patch -L:func2:file.c --parents >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.23.0.349.g73f10e387d
SZEDER Gábor· Aug 18, 2019, 18:28 UTC · re: SZEDER Gábor · lore

[RFC PATCH 4/5] line-log: more responsive, incremental 'git log -L'

The current line-level log implementation performs a preprocessing step in prepare_revision_walk(), during which the line_log_filter() function filters and rewrites history to keep only commits modifying the given line range. This preprocessing affects both responsiveness and correctness:

  - Git doesn't produce any output during this preprocessing step.
    Checking whether a commit modified the given line range is
    somewhat expensive, so depending on the size of the given revision
    range this preprocessing can result in a significant delay before
    the first commit is shown.
  - Limiting the number of displayed commits (e.g. 'git log -3 -L...')
    doesn't limit the amount of work during preprocessing, because
    that limit is applied during history traversal.  Alas, by that
    point this expensive preprocessing step has already churned
    through the whole revision range to find all commits modifying the
    revision range, even though only a few of them need to be shown.
  - It rewrites parents, with no way to turn it off.  Without the user
    explicitly requesting parent rewriting any parent object ID shown
    should be that of the immediate parent, just like in case of a
    pathspec-limited history traversal without parent rewriting.
    However, after that preprocessing step rewrote history, the
    subsequent "regular" history traversal (i.e. get_revision() in a
    loop) only sees commits modifying the given line range.
    Consequently, it can only show the object ID of the last ancestor
    that modified the given line range (which might happen to be the
    immediate parent, but many-many times it isn't).

This patch addresses both the correctness and, at least for the common case, the responsiveness issues by integrating line-level log filtering into the regular revision walking machinery:

  - Make process_ranges_arbitrary_commit(), the static function in
    'line-log.c' deciding whether a commit modifies the given line
    range, public by removing the static keyword and adding the
    'line_log_' prefix, so it can be called from other parts of the
    revision walking machinery.
  - If the user didn't explicitly ask for parent rewriting (which, I
    believe, is the most common case):
    - Call this now-public function during regular history traversal,
      namely from get_commit_action() to ignore any commits not
      modifying the given line range.
      Note that while this check is relatively expensive, it must be
      performed before other, much cheaper conditions, because the
      tracked line range must be adjusted even when the commit will
      end up being ignored by other conditions.
    - Skip the line_log_filter() call, i.e. the expensive
      preprocessing step, in prepare_revision_walk(), because, thanks
      to the above points, the revision walking machinery is now able
      to filter out commits not modifying the given line range while
      traversing history.
      This way the regular history traversal sees the unmodified
      history, and is therefore able to print the object ids of the
      immediate parents of the listed commits.  The eliminated
      preprocessing step can greatly reduce the delay before the first
      commit is shown, see the numbers below.
  - However, if the user did explicitly ask for parent rewriting via
    '--parents' or a similar option, then stick with the current
    implementation for now, i.e. perform that expensive filtering and
    history rewriting in the preprocessing step just like we did
    before, leaving the initial delay as long as it was.

I tried to integrate line-level log filtering with parent rewriting into the regular history traversal, but, unfortunately, several subtleties resisted... :) Maybe someday we'll figure out how to do that, but until then at least the simple and common (i.e. without parent rewriting) 'git log -L:func:file' commands can benefit from the reduced delay.

This change makes the failing 'parent oids without parent rewriting' test in 't4211-line-log.sh' succeed.

The reduced delay is most noticable when there's a commit modifying the line range near the tip of a large-ish revision range:

  # no parent rewriting requested, no commit-graph present
  $ time git --no-pager log -L:read_alternate_refs:sha1-file.c -1 v2.23.0
  Before:
    real    0m9.570s
    user    0m9.494s
    sys     0m0.076s
  After:
    real    0m0.718s
    user    0m0.674s
    sys     0m0.044s

A significant part of the remaining delay is spent reading and parsing commit objects in limit_list(). With the help of the commit-graph we can eliminate most of that reading and parsing overhead, so here are the timing results of the same command as above, but this time using the commit-graph:

  Before:
    real    0m8.874s
    user    0m8.816s
    sys     0m0.057s
  After:
    real    0m0.107s
    user    0m0.091s
    sys     0m0.013s
The next patch will further reduce the remaining delay.

To be clear: this patch doesn't actually optimize the line-level log, but merely moves most of the work from the preprocessing step to the history travelsal, so the commits modifying the line range can be shown as soon as they are processed, and the traversal can be terminated as soon as the given number of commits are shown. Consequently, listing the full history of a line range, potentially all the way to the root commit, will take the same time as before (but at least the user might start reading the output earlier). Furthermore, if the most recent commit modifying the line range is far away from the starting revision, then that initial delay will still be significant.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
Notes:
    Regarding that "most common case": I know, I know, one should not
    extrapolate only from his own usage patterns...  But FWIW, I've been
    using various versions of this patch for over two years now, and never
    missed the rewritten parents.  And just pulled a couple of years worth
    of ~/.bash_history files from backups, and there was not a single
    occasion where I used line-level log with parent rewriting (apart from
    testing these changes).
 line-log.c          |  4 ++--
 line-log.h          |  2 ++
 revision.c          | 27 ++++++++++++++++++++++++++-
 t/t4211-line-log.sh |  2 +-
 4 files changed, 31 insertions(+), 4 deletions(-)
Show changes to 4 files +31 −4

line-log.c, line-log.h, revision.c, t/t4211-line-log.sh

diff --git a/line-log.c b/line-log.c
index 3aff1849e7..772ab57d52 100644
--- a/line-log.c
+++ b/line-log.c
@@ -1194,7 +1194,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
 	/* NEEDSWORK leaking like a sieve */
 }
 
-static int process_ranges_arbitrary_commit(struct rev_info *rev, struct commit *commit)
+int line_log_process_ranges_arbitrary_commit(struct rev_info *rev, struct commit *commit)
 {
 	struct line_log_data *range = lookup_line_range(rev, commit);
 	int changed = 0;
@@ -1237,7 +1237,7 @@ int line_log_filter(struct rev_info *rev)
 	while (list) {
 		struct commit_list *to_free = NULL;
 		commit = list->item;
-		if (process_ranges_arbitrary_commit(rev, commit)) {
+		if (line_log_process_ranges_arbitrary_commit(rev, commit)) {
 			*pp = list;
 			pp = &list->next;
 		} else
diff --git a/line-log.h b/line-log.h
index 882c5055bb..82ae8d98a4 100644
--- a/line-log.h
+++ b/line-log.h
@@ -54,6 +54,8 @@ struct line_log_data {
 void line_log_init(struct rev_info *rev, const char *prefix, struct string_list *args);
 
 int line_log_filter(struct rev_info *rev);
+int line_log_process_ranges_arbitrary_commit(struct rev_info *rev,
+						    struct commit *commit);
 
 int line_log_print(struct rev_info *rev, struct commit *commit);
 
diff --git a/revision.c b/revision.c
index 07412297f0..6bdfcb38cd 100644
--- a/revision.c
+++ b/revision.c
@@ -36,6 +36,8 @@ static const char *term_good;
 
 implement_shared_commit_slab(revision_sources, char *);
 
+static inline int want_ancestry(const struct rev_info *revs);
+
 void show_object_with_name(FILE *out, struct object *obj, const char *name)
 {
 	const char *p;
@@ -3359,7 +3361,14 @@ int prepare_revision_walk(struct rev_info *revs)
 			sort_in_topological_order(&revs->commits, revs->sort_order);
 	} else if (revs->topo_order)
 		init_topo_walk(revs);
-	if (revs->line_level_traverse)
+	if (revs->line_level_traverse && want_ancestry(revs))
+		/*
+		 * At the moment we can only do line-level log with parent
+		 * rewriting by performing this expensive pre-filtering step.
+		 * If parent rewriting is not requested, then we rather
+		 * perform the line-level log filtering during the regular
+		 * history traversal.
+		 */
 		line_log_filter(revs);
 	if (revs->simplify_merges)
 		simplify_merges(revs);
@@ -3569,6 +3578,22 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi
 		return commit_ignore;
 	if (commit->object.flags & UNINTERESTING)
 		return commit_ignore;
+	if (revs->line_level_traverse && !want_ancestry(revs)) {
+		/*
+		 * In case of line-level log with parent rewriting
+		 * prepare_revision_walk() already took care of all line-level
+		 * log filtering, and there is nothing left to do here.
+		 *
+		 * If parent rewriting was not requested, then this is the
+		 * place to perform the line-level log filtering.  Notably,
+		 * this check, though expensive, must come before the other,
+		 * cheaper filtering conditions, because the tracked line
+		 * ranges must be adjusted even when the commit will end up
+		 * being ignored based on other conditions.
+		 */
+		if (!line_log_process_ranges_arbitrary_commit(revs, commit))
+			return commit_ignore;
+	}
 	if (revs->min_age != -1 &&
 	    comparison_date(revs, commit) > revs->min_age)
 			return commit_ignore;
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index c378a453de..8096208abb 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -180,7 +180,7 @@ test_expect_success 'setup for checking line-log and parent oids' '
 '
 
 # Parent oid should be from immediate parent.
-test_expect_failure 'parent oids without parent rewriting' '
+test_expect_success 'parent oids without parent rewriting' '
 	cat >expect <<-EOF &&
 	$head_oid $prev_oid Modify func2() in file.c
 	$root_oid  Add func1() and func2() in file.c
-- 
2.23.0.349.g73f10e387d
SZEDER Gábor· Aug 19, 2019, 12:34 UTC · re: SZEDER Gábor · lore

Re: [RFC PATCH 4/5] line-log: more responsive, incremental 'git log -L'

On Sun, Aug 18, 2019 at 08:28:00PM +0200, SZEDER Gábor wrote:
Show 18 quoted lines
> The current line-level log implementation performs a preprocessing
> step in prepare_revision_walk(), during which the line_log_filter()
> function filters and rewrites history to keep only commits modifying
> the given line range.  This preprocessing affects both responsiveness
> and correctness:
> 
>   - Git doesn't produce any output during this preprocessing step.
>     Checking whether a commit modified the given line range is
>     somewhat expensive, so depending on the size of the given revision
>     range this preprocessing can result in a significant delay before
>     the first commit is shown.
> 
>   - Limiting the number of displayed commits (e.g. 'git log -3 -L...')
>     doesn't limit the amount of work during preprocessing, because
>     that limit is applied during history traversal.  Alas, by that
>     point this expensive preprocessing step has already churned
>     through the whole revision range to find all commits modifying the
>     revision range, even though only a few of them need to be shown.
s/revision range/line range/
Derrick Stolee· Aug 19, 2019, 12:43 UTC · re: SZEDER Gábor · lore

Re: [RFC PATCH 4/5] line-log: more responsive, incremental 'git log -L'

On 8/18/2019 2:28 PM, SZEDER Gábor wrote:
> To be clear: this patch doesn't actually optimize the line-level log,
> but merely moves most of the work from the preprocessing step to the
> history travelsal, so the commits modifying the line range can be
s/travelsal/traversal/
-Stolee
SZEDER Gábor· Aug 18, 2019, 18:28 UTC · re: SZEDER Gábor · lore

[RFC PATCH 5/5] line-log: try to use generation number-based topo-ordering

The previous patch made it possible to perform line-level filtering during history traversal instead of in an expensive preprocessing step, but it still requires some simpler preprocessing steps, notably topo-ordering. However, nowadays we have commit-graphs storing generation numbers, which make it possible to incrementally traverse the history in topological order, without the preparatory limit_list() and sort_in_topological_order() steps; see b45424181e (revision.c: generation-based topo-order algorithm, 2018-11-01).

This patch combines the two, so we can do both the topo-ordering and the line-level filtering during history traversal, eliminating even those simpler preprocessing steps, and thus further reducing the delay before showing the first commit modifying the given line range.

The 'revs->limited' flag plays the central role in this, because, due to limitations of the current implementation, the generation number-based topo-ordering is only enabled when this flag remains unset. Line-level log, however, always sets this flag in setup_revisions() ever since the feature was introduced in 12da1d1f6f (Implement line-history search (git log -L), 2013-03-28). The reason for setting 'limited' is unclear, though, because the line-level log itself doesn't directly depend on it, and it doesn't affect how the limit_list() function limits the revision range. However, there is an indirect dependency: the line-level log requires topo-ordering, and the "traditional" sort_in_topological_order() requires an already limited commit list since e6c3505b44 (Make sure we generate the whole commit list before trying to sort it topologically, 2005-07-06). The new, generation numbers-based topo-ordering doesn't require a limited commit list anymore.

So don't set 'revs->limited' for line-level log, unless it is really necessary, namely:

  - The user explicitly requested parent rewriting, because that is
    still done in the line_log_filter() preprocessing step (see
    previous patch), which requires sort_in_topological_order() and in
    turn limit_list() as well.
  - A commit-graph file is not available or it doesn't yet contain
    generation numbers.  In these cases we had to fall back on
    sort_in_topological_order() and in turn limit_list().  The
    existing condition with generation_numbers_enabled() has already
    ensured that the 'limited' flag is set in these cases; this patch
    just makes sure that the line-level log sets 'revs->topo_order'
    before that condition.

While the reduced delay before showing the first commit is measurable in git.git, it takes a bigger repository to make it clearly noticable. In both cases below the line ranges were chosen so that they were modified rather close to the starting revisions, so the effect of this change is most noticable.

  # git.git
  $ time git --no-pager log -L:read_alternate_refs:sha1-file.c -1 v2.23.0
  Before:
    real    0m0.107s
    user    0m0.091s
    sys     0m0.013s
  After:
    real    0m0.058s
    user    0m0.050s
    sys     0m0.005s
  # linux.git
  $ time git --no-pager log \
    -L:build_restore_work_registers:arch/mips/mm/tlbex.c -1 v5.2
  Before:
    real   0m1.129s
    user   0m1.061s
    sys    0m0.069s
  After:
    real   0m0.096s
    user   0m0.087s
    sys    0m0.009s
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
Notes:
    FWIW, that line-level log sets 'limited' in addition to 'topo_order'
    thing was already part of the first submitted iteration of the
    line-level log patch series:
    
    https://public-inbox.org/git/1277558857-23103-4-git-send-email-struggleyb.nku@gmail.com/#Z30revision.c
    
    But it was never discussed during review.
 revision.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
Show changes to revision.c +6 −5
diff --git a/revision.c b/revision.c
index 6bdfcb38cd..7a9dc54771 100644
--- a/revision.c
+++ b/revision.c
@@ -2658,6 +2658,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 	if (revs->diffopt.objfind)
 		revs->simplify_history = 0;
 
+	if (revs->line_level_traverse) {
+		if (want_ancestry(revs))
+			revs->limited = 1;
+		revs->topo_order = 1;
+	}
+
 	if (revs->topo_order && !generation_numbers_enabled(the_repository))
 		revs->limited = 1;
 
@@ -2677,11 +2683,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 
 	revs->diffopt.abbrev = revs->abbrev;
 
-	if (revs->line_level_traverse) {
-		revs->limited = 1;
-		revs->topo_order = 1;
-	}
-
 	diff_setup_done(&revs->diffopt);
 
 	grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED,
-- 
2.23.0.349.g73f10e387d
Derrick Stolee· Aug 19, 2019, 12:00 UTC · re: SZEDER Gábor · lore

Re: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

On 8/18/2019 2:27 PM, SZEDER Gábor wrote:
Show 16 quoted lines
> Line-level log performs a preprocessing step in
> prepare_revision_walk(), during which it filters and rewrites history
> to keep only commits modifying the given line range.  This
> preprocessing causes significant delay before the first commit is
> shown, wastes CPU time when the user asks only for a few commits, and
> does parent rewriting with no way to turn it off.
> 
> This patch series addresses these issues by integrating line-level log
> filtering into the revision walking machinery and making it work
> together with generation number-based topo-ordering (though for now
> only in the case when the user doesn't explicitly asks for parent
> rewriting, which is probably the common case).
> 
> The first two patches are quite straightforward (and arguably somewhat
> unrelated), but the rest deals with history traversal and parent
> rewriting, which I don't usually do, hence the RFC.
Hi Szeder,

Thanks for sending this series! I'm particularly excited about it because we recently got a bug report from a user in the Windows OS repo about "git log -L" being very slow. I put it on the backlog [1] but haven't had time to investigate it myself. After we are done updating to v2.23.0 [2], I'll have time to test your changes on the Windows repo. I anticipate your change to provide a massive boost.

In the meantime, your first three patches look good to me. I'll dig more into the last two at the same time as I run performance tests.

Thanks, -Stolee

[1] https://github.com/microsoft/git/issues/166 [2] https://github.com/microsoft/git/pull/165

SZEDER Gábor· Aug 19, 2019, 13:03 UTC · re: Derrick Stolee · lore

Re: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

On Mon, Aug 19, 2019 at 08:00:11AM -0400, Derrick Stolee wrote:
Show 27 quoted lines
> On 8/18/2019 2:27 PM, SZEDER Gábor wrote:
> > Line-level log performs a preprocessing step in
> > prepare_revision_walk(), during which it filters and rewrites history
> > to keep only commits modifying the given line range.  This
> > preprocessing causes significant delay before the first commit is
> > shown, wastes CPU time when the user asks only for a few commits, and
> > does parent rewriting with no way to turn it off.
> > 
> > This patch series addresses these issues by integrating line-level log
> > filtering into the revision walking machinery and making it work
> > together with generation number-based topo-ordering (though for now
> > only in the case when the user doesn't explicitly asks for parent
> > rewriting, which is probably the common case).
> > 
> > The first two patches are quite straightforward (and arguably somewhat
> > unrelated), but the rest deals with history traversal and parent
> > rewriting, which I don't usually do, hence the RFC.
> 
> Hi Szeder,
> 
> Thanks for sending this series! I'm particularly excited about it
> because we recently got a bug report from a user in the Windows OS
> repo about "git log -L" being very slow. I put it on the backlog [1]
> but haven't had time to investigate it myself. After we are done
> updating to v2.23.0 [2], I'll have time to test your changes on
> the Windows repo. I anticipate your change to provide a massive
> boost.

Well, it depends on what you mean by "boost"... As discussed in patch 4's commit message, this series doesn't really optimizes much, and the total amount of work to be done remains the same, except that 'git log -L... -<N>' will be able to return early. So when you benchmark it with e.g. 'time git log -L... >/dev/null', then you won't see much difference, as it will still take just about as looooong as before, apart from the faster generation numbers-based topo-ordering. (But I have a few WIP patches waiting to be cleaned up that might bring about 3-4x speedup in general.)

In the meantime, until these changes trickle into a Git release, for a faster line-level log I would recommend to:

  - Limit the revision range up front, i.e.:
      git log -L... ^a-not-too-old-version
    because this can greatly reduce the amount of commits that that
    expensive preprocessing step has to churn through.
  - Use '--no-renames'.  Although it won't follow the evolution of the
    line range over file renames, this might be an acceptable
    compromise.  (this is what those WIP patches are focusing on)
  - Or both.
Derrick Stolee· Aug 19, 2019, 14:50 UTC · re: SZEDER Gábor · lore

Re: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

On 8/19/2019 9:03 AM, SZEDER Gábor wrote:
Show 54 quoted lines
> On Mon, Aug 19, 2019 at 08:00:11AM -0400, Derrick Stolee wrote:
>> On 8/18/2019 2:27 PM, SZEDER Gábor wrote:
>>> Line-level log performs a preprocessing step in
>>> prepare_revision_walk(), during which it filters and rewrites history
>>> to keep only commits modifying the given line range.  This
>>> preprocessing causes significant delay before the first commit is
>>> shown, wastes CPU time when the user asks only for a few commits, and
>>> does parent rewriting with no way to turn it off.
>>>
>>> This patch series addresses these issues by integrating line-level log
>>> filtering into the revision walking machinery and making it work
>>> together with generation number-based topo-ordering (though for now
>>> only in the case when the user doesn't explicitly asks for parent
>>> rewriting, which is probably the common case).
>>>
>>> The first two patches are quite straightforward (and arguably somewhat
>>> unrelated), but the rest deals with history traversal and parent
>>> rewriting, which I don't usually do, hence the RFC.
>>
>> Hi Szeder,
>>
>> Thanks for sending this series! I'm particularly excited about it
>> because we recently got a bug report from a user in the Windows OS
>> repo about "git log -L" being very slow. I put it on the backlog [1]
>> but haven't had time to investigate it myself. After we are done
>> updating to v2.23.0 [2], I'll have time to test your changes on
>> the Windows repo. I anticipate your change to provide a massive
>> boost.
> 
> Well, it depends on what you mean by "boost"...  As discussed in patch
> 4's commit message, this series doesn't really optimizes much, and the
> total amount of work to be done remains the same, except that 'git log
> -L... -<N>' will be able to return early.  So when you benchmark it
> with e.g. 'time git log -L... >/dev/null', then you won't see much
> difference, as it will still take just about as looooong as before,
> apart from the faster generation numbers-based topo-ordering.  (But I
> have a few WIP patches waiting to be cleaned up that might bring about
> 3-4x speedup in general.)
> 
> In the meantime, until these changes trickle into a Git release, for a
> faster line-level log I would recommend to:
> 
>   - Limit the revision range up front, i.e.:
> 
>       git log -L... ^a-not-too-old-version
> 
>     because this can greatly reduce the amount of commits that that
>     expensive preprocessing step has to churn through.
> 
>   - Use '--no-renames'.  Although it won't follow the evolution of the
>     line range over file renames, this might be an acceptable
>     compromise.  (this is what those WIP patches are focusing on)
> 
>   - Or both.

Usually when I'm testing something involving the --topo-order logic, I'll use a simple "-10" to limit to something similar to a "first page".

In this line-log case, I'll use "-1" to just get the top result, as that is essentially how long it takes before the user gets some feedback.

Here are the results using a random path I picked out from the Windows repo (it was only changed ~10 times in the 4.5 million commits):

Before:

real 2m7.308s real 2m8.572s

With Patch 4:

real 0m38.628s real 0m38.477s

With Patch 5:

real 0m24.685s real 0m24.310s

For the specific file in the bug report from a real user, I got these numbers:

real 0m32.293s (patch 4) real 0m19.362s (patch 5)

Note that I don't include the "without patch" numbers. For some reason the path provided is particularly nasty and caused 20,000+ missing blobs to be downloaded one-by-one (remember: VFS for Git has many partial-clone-like behaviors). I canceled my test after 55 minutes. I'll dig in more to see what is going on, since only 37 commits actually change that path.

Thanks so much for finding these "easy" wins. Your changes are nicely isolated, but give us a target to improve even further!

I expect that we will incorporate your commits into microsoft/git very early.

Thanks, -Stolee

SZEDER Gábor· Aug 19, 2019, 15:02 UTC · re: Derrick Stolee · lore

Re: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

On Mon, Aug 19, 2019 at 10:50:48AM -0400, Derrick Stolee wrote:
Show 6 quoted lines
> Note that I don't include the "without patch" numbers. For some
> reason the path provided is particularly nasty and caused 20,000+
> missing blobs to be downloaded one-by-one (remember: VFS for Git
> has many partial-clone-like behaviors). I canceled my test after 55
> minutes. I'll dig in more to see what is going on, since only 37
> commits actually change that path.

Don't bother digging into it, I know why it happens (and how to avoid it! :), but don't have the time right now to explain.

Derrick Stolee· Aug 19, 2019, 16:12 UTC · re: SZEDER Gábor · lore

Re: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

On 8/19/2019 11:02 AM, SZEDER Gábor wrote:
Show 10 quoted lines
> On Mon, Aug 19, 2019 at 10:50:48AM -0400, Derrick Stolee wrote:
>> Note that I don't include the "without patch" numbers. For some
>> reason the path provided is particularly nasty and caused 20,000+
>> missing blobs to be downloaded one-by-one (remember: VFS for Git
>> has many partial-clone-like behaviors). I canceled my test after 55
>> minutes. I'll dig in more to see what is going on, since only 37
>> commits actually change that path.
> 
> Don't bother digging into it, I know why it happens (and how to avoid
> it! :), but don't have the time right now to explain.
Great!  I look forward to your explanation and fix later.

Just to be sure we've got the same issue, here is a section of the call stack in the hot portion:

line_log_filter
+ queue_diffs
  + diffcore_std
    + diffcore_rename
      + diff_populate_filespec

Thanks, -Stolee

SZEDER Gábor· Aug 21, 2019, 11:07 UTC · re: Derrick Stolee · lore

Re: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

On Mon, Aug 19, 2019 at 12:12:32PM -0400, Derrick Stolee wrote:
Show 22 quoted lines
> On 8/19/2019 11:02 AM, SZEDER Gábor wrote:
> > On Mon, Aug 19, 2019 at 10:50:48AM -0400, Derrick Stolee wrote:
> >> Note that I don't include the "without patch" numbers. For some
> >> reason the path provided is particularly nasty and caused 20,000+
> >> missing blobs to be downloaded one-by-one (remember: VFS for Git
> >> has many partial-clone-like behaviors). I canceled my test after 55
> >> minutes. I'll dig in more to see what is going on, since only 37
> >> commits actually change that path.
> > 
> > Don't bother digging into it, I know why it happens (and how to avoid
> > it! :), but don't have the time right now to explain.
> 
> Great!  I look forward to your explanation and fix later.
> 
> Just to be sure we've got the same issue, here is a section of the
> call stack in the hot portion:
> 
> line_log_filter
> + queue_diffs
>   + diffcore_std
>     + diffcore_rename
>       + diff_populate_filespec

Hmm, interesting. Certainly most of the time is wasted in queue_diffs(), but in my perf measurements diff_tree_oid() is responsible for most of that, not diffcore_std(). This might still be the same issue, though, but perhaps VFS for Git shifts the balance.

We'll see, here are my patches to address that diff_tree_oid() slowness:

https://public-inbox.org/git/20190821110424.18184-1-szeder.dev@gmail.com/T/
Derrick Stolee· Apr 9, 2020, 12:17 UTC · re: SZEDER Gábor · lore

Re: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

On 8/18/2019 2:27 PM, SZEDER Gábor wrote:
Show 24 quoted lines
> Line-level log performs a preprocessing step in
> prepare_revision_walk(), during which it filters and rewrites history
> to keep only commits modifying the given line range.  This
> preprocessing causes significant delay before the first commit is
> shown, wastes CPU time when the user asks only for a few commits, and
> does parent rewriting with no way to turn it off.
> 
> This patch series addresses these issues by integrating line-level log
> filtering into the revision walking machinery and making it work
> together with generation number-based topo-ordering (though for now
> only in the case when the user doesn't explicitly asks for parent
> rewriting, which is probably the common case).
> 
> The first two patches are quite straightforward (and arguably somewhat
> unrelated), but the rest deals with history traversal and parent
> rewriting, which I don't usually do, hence the RFC.
> 
> 
> SZEDER Gábor (5):
>   completion: offer '--(no-)patch' among 'git log' options
>   line-log: remove unused fields from 'struct line_log_data'
>   t4211-line-log: add tests for parent oids
>   line-log: more responsive, incremental 'git log -L'
>   line-log: try to use generation number-based topo-ordering
Hi Szeder,

I was taking inventory of our issues especially around history now that the changed-path Bloom filters are close to wrapping up. What's the status on this RFC? Looking at it now, I understand the situation better and could help review a bit more than before. Do you have more context as to the situation on this series?

Thanks, -Stolee

SZEDER Gábor· Apr 24, 2020, 09:02 UTC · re: Derrick Stolee · lore

Re: [RFC PATCH 0/5] line-log: towards a more responsive, incremental 'git log -L'

On Thu, Apr 09, 2020 at 08:17:41AM -0400, Derrick Stolee wrote:
Show 30 quoted lines
> On 8/18/2019 2:27 PM, SZEDER Gábor wrote:
> > Line-level log performs a preprocessing step in
> > prepare_revision_walk(), during which it filters and rewrites history
> > to keep only commits modifying the given line range.  This
> > preprocessing causes significant delay before the first commit is
> > shown, wastes CPU time when the user asks only for a few commits, and
> > does parent rewriting with no way to turn it off.
> > 
> > This patch series addresses these issues by integrating line-level log
> > filtering into the revision walking machinery and making it work
> > together with generation number-based topo-ordering (though for now
> > only in the case when the user doesn't explicitly asks for parent
> > rewriting, which is probably the common case).
> > 
> > The first two patches are quite straightforward (and arguably somewhat
> > unrelated), but the rest deals with history traversal and parent
> > rewriting, which I don't usually do, hence the RFC.
> > 
> > 
> > SZEDER Gábor (5):
> >   completion: offer '--(no-)patch' among 'git log' options
> >   line-log: remove unused fields from 'struct line_log_data'
> >   t4211-line-log: add tests for parent oids
> >   line-log: more responsive, incremental 'git log -L'
> >   line-log: try to use generation number-based topo-ordering
> 
> Hi Szeder,
> 
> I was taking inventory of our issues especially around history now
> that the changed-path Bloom filters are close to wrapping up.
Well, I'm about to stir it up over the weekend...
> What's
> the status on this RFC? Looking at it now, I understand the situation
> better and could help review a bit more than before. Do you have more
> context as to the situation on this series?

Sadly, I haven't touched this patch series since then, other than rebasing it on top of new releases once or twice, but since v2.23 not even that. I think I run into some conflicts and was not in the mood to resolve them, because with a2bb801f6a (line-log: avoid unnecessary full tree diffs, 2019-08-21) the performance benefits are much lower, so it was not that pressing...

I think patch 4 in itself is not really the right way to integrate line-log into the revision walking machinery:

  - Line-log follows full-file renames, but it doesn't actually use
    '--follow', but rather implements its own logic to detect them.
    This logic is in some ways better, than '--follow', notably it can
    follow multiple paths at once, while '--follow' only allows a
    single path.
    I think the rename following logic should be extracted from
    line-log, and it should be used to implement '--follow', removing
    some of its restrictions.
  - Line-log should then be ported to use the revamped '--follow'.
  - And then it's finally time for something like that patch 4, and to
    have some "fun" with making explicitly requested parent rewriting
    work (I can only remember that whenever I tried to make that work
    my brain started to hurt :)
 
Anyway, I think the first three patches are worth having.

← back to recent threads