Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: git/git
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 20514004dd
Choose a base ref
...
head repository: git/git
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f32dde8c12
Choose a head ref
  • 5 commits
  • 6 files changed
  • 2 contributors

Commits on May 11, 2020

  1. 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 12da1d1 (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>
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
    szeder authored and gitster committed May 11, 2020
    Configuration menu
    Copy the full SHA
    d554672 View commit details
    Browse the repository at this point in the history
  2. 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>
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
    szeder authored and gitster committed May 11, 2020
    Configuration menu
    Copy the full SHA
    48da94b View commit details
    Browse the repository at this point in the history
  3. 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 traversal, 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.
    
    Additional testing by Derrick Stolee: In the Linux kernel repository,
    the MAINTAINERS file was changed ~3,500 times across the ~915,000
    commits. In addition to that edit frequency, the file itself is quite
    large (~18,700 lines). This means that a significant portion of the
    computation is taken up by computing the patch-diff of the file. This
    patch improves the real time it takes to output the first result quite
    a bit:
    
    Command: git log -L 100,200:MAINTAINERS -n 1 >/dev/null
     Before: 3.88 s
      After: 0.71 s
    
    If we drop the "-n 1" in the command, then there is no change in
    end-to-end process time. This is because the command still needs to
    walk the entire commit history, which negates the point of this
    patch. This is expected.
    
    As a note for future reference, the ~4.3 seconds in the old code
    spends ~2.6 seconds computing the patch-diffs, and the rest of the
    time is spent walking commits and computing diffs for which paths
    changed at each commit. The changed-path Bloom filters could improve
    the end-to-end computation time (i.e. no "-n 1" in the command).
    
    Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
    szeder authored and gitster committed May 11, 2020
    Configuration menu
    Copy the full SHA
    3cb9d2b View commit details
    Browse the repository at this point in the history
  4. 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 b454241 (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 12da1d1
    (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 e6c3505 (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
    
    Additional testing by Derrick Stolee: Since this patch improves
    the performance for the first result, I repeated the experiment
    from the previous patch on the Linux kernel repository, reporting
    real time here:
    
        Command: git log -L 100,200:MAINTAINERS -n 1 >/dev/null
         Before: 0.71 s
          After: 0.05 s
    
    Now, we have dropped the full topo-order of all ~910,000 commits
    before reporting the first result. The remaining performance
    improvements then are:
    
     1. Update the parent-rewriting logic to be incremental similar to
        how "git log --graph" behaves.
    
     2. Use changed-path Bloom filters to reduce the time spend in the
        tree-diff to see if the path(s) changed.
    
    Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
    szeder authored and gitster committed May 11, 2020
    Configuration menu
    Copy the full SHA
    002933f View commit details
    Browse the repository at this point in the history
  5. line-log: integrate with changed-path Bloom filters

    The previous changes to the line-log machinery focused on making the
    first result appear faster. This was achieved by no longer walking the
    entire commit history before returning the early results. There is still
    another way to improve the performance: walk most commits much faster.
    Let's use the changed-path Bloom filters to reduce time spent computing
    diffs.
    
    Since the line-log computation requires opening blobs and checking the
    content-diff, there is still a lot of necessary computation that cannot
    be replaced with changed-path Bloom filters. The part that we can reduce
    is most effective when checking the history of a file that is deep in
    several directories and those directories are modified frequently. In
    this case, the computation to check if a commit is TREESAME to its first
    parent takes a large fraction of the time. That is ripe for improvement
    with changed-path Bloom filters.
    
    We must ensure that prepare_to_use_bloom_filters() is called in
    revision.c so that the bloom_filter_settings are loaded into the struct
    rev_info from the commit-graph. Of course, some cases are still
    forbidden, but in the line-log case the pathspec is provided in a
    different way than normal.
    
    Since multiple paths and segments could be requested, we compute the
    struct bloom_key data dynamically during the commit walk. This could
    likely be improved, but adds code complexity that is not valuable at
    this time.
    
    There are two cases to care about: merge commits and "ordinary" commits.
    Merge commits have multiple parents, but if we are TREESAME to our first
    parent in every range, then pass the blame for all ranges to the first
    parent. Ordinary commits have the same condition, but each is done
    slightly differently in the process_ranges_[merge|ordinary]_commit()
    methods. By checking if the changed-path Bloom filter can guarantee
    TREESAME, we can avoid that tree-diff cost. If the filter says "probably
    changed", then we need to run the tree-diff and then the blob-diff if
    there was a real edit.
    
    The Linux kernel repository is a good testing ground for the performance
    improvements claimed here. There are two different cases to test. The
    first is the "entire history" case, where we output the entire history
    to /dev/null to see how long it would take to compute the full line-log
    history. The second is the "first result" case, where we find how long
    it takes to show the first value, which is an indicator of how quickly a
    user would see responses when waiting at a terminal.
    
    To test, I selected the paths that were changed most frequently in the
    top 10,000 commits using this command (stolen from StackOverflow [1]):
    
    	git log --pretty=format: --name-only -n 10000 | sort | \
    		uniq -c | sort -rg | head -10
    
    which results in
    
        121 MAINTAINERS
         63 fs/namei.c
         60 arch/x86/kvm/cpuid.c
         59 fs/io_uring.c
         58 arch/x86/kvm/vmx/vmx.c
         51 arch/x86/kvm/x86.c
         45 arch/x86/kvm/svm.c
         42 fs/btrfs/disk-io.c
         42 Documentation/scsi/index.rst
    
    (along with a bogus first result). It appears that the path
    arch/x86/kvm/svm.c was renamed, so we ignore that entry. This leaves the
    following results for the real command time:
    
    |                              | Entire History  | First Result    |
    | Path                         | Before | After  | Before | After  |
    |------------------------------|--------|--------|--------|--------|
    | MAINTAINERS                  | 4.26 s | 3.87 s | 0.41 s | 0.39 s |
    | fs/namei.c                   | 1.99 s | 0.99 s | 0.42 s | 0.21 s |
    | arch/x86/kvm/cpuid.c         | 5.28 s | 1.12 s | 0.16 s | 0.09 s |
    | fs/io_uring.c                | 4.34 s | 0.99 s | 0.94 s | 0.27 s |
    | arch/x86/kvm/vmx/vmx.c       | 5.01 s | 1.34 s | 0.21 s | 0.12 s |
    | arch/x86/kvm/x86.c           | 2.24 s | 1.18 s | 0.21 s | 0.14 s |
    | fs/btrfs/disk-io.c           | 1.82 s | 1.01 s | 0.06 s | 0.05 s |
    | Documentation/scsi/index.rst | 3.30 s | 0.89 s | 1.46 s | 0.03 s |
    
    It is worth noting that the least speedup comes for the MAINTAINERS file
    which is
    
     * edited frequently,
     * low in the directory heirarchy, and
     * quite a large file.
    
    All of those points lead to spending more time doing the blob diff and
    less time doing the tree diff. Still, we see some improvement in that
    case and significant improvement in other cases. A 2-4x speedup is
    likely the more typical case as opposed to the small 5% change for that
    file.
    
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
    derrickstolee authored and gitster committed May 11, 2020
    Configuration menu
    Copy the full SHA
    f32dde8 View commit details
    Browse the repository at this point in the history
Loading