Subject: Re: [BUG?] Major performance issue with some commands on our repo's master branch

From: Kyle Meyer <[email-masked]>
Date: Wed, 08 Jun 2022 21:27:43 -0400

Jeff King writes:

> I suspect the issue may be quite subtle. Even you asked for
> "--no-patch", the underlying diff may still be used for other things.
> For example, simplifying away TREESAME commits. I.e., ones which did not
> change anything from their parents after applying path restrictions,
> diff-filters, etc. There may be other cases, too (e.g., --follow).
>
> I think the code could be written to realize that none of those features
> are in use, and disable the diff entirely in favor of checking whether
> the two trees has the same object id. That would yield _mostly_ the same
> behavior, though there are probably corner cases (e.g., a tree with an
> odd mode entry, say, may get parsed so as to produce an empty diff, even
> though it's not byte for byte identical). That may be an acceptable
> tradeoff. But I think the code would be a bit brittle (it needs to know
> about all the cases where a diff might matter, and we may add more
> later).

Do you think it'd be safe to make --no-patch imply --diff-merges=off, as
Tao suggested elsewhere in this thread?

  https://lore.kernel.org/git/CAPMMpog-7eDOrgSU9GjV4G9rk5RkL-PJhaUAO3_0p2YxfRf=[email-masked]

If so, it seems like that'd be a good way to get speedups for some merge
commits.  For example, here are hyperfine timings for the current tip of
git.git's master branch:

  Benchmark #1: git show --no-patch --format=%h 1e59178e3f
    Time (mean ± σ):      47.8 ms ±   1.5 ms    [User: 43.2 ms, System: 4.6 ms]
    Range (min … max):    46.8 ms …  54.4 ms    59 runs
   
    Warning: Statistical outliers were detected. Consider re-running
    this benchmark on a quiet PC without any interferences from other
    programs. It might help to use the '--warmup' or '--prepare'
    options.
   
  Benchmark #2: git show --no-patch --diff-merges=off --format=%h 1e59178e3f
    Time (mean ± σ):       3.2 ms ±   0.2 ms    [User: 2.5 ms, System: 0.8 ms]
    Range (min … max):     2.9 ms …   6.8 ms    688 runs
   
    Warning: Command took less than 5 ms to complete. Results might be
    inaccurate.
    
    Warning: Statistical outliers were detected. Consider [...]
    options.
   
  Benchmark #3: git log --no-walk --format=%h 1e59178e3f
    Time (mean ± σ):       3.2 ms ±   0.1 ms    [User: 2.4 ms, System: 0.8 ms]
    Range (min … max):     2.9 ms …   4.2 ms    697 runs
   
    Warning: Command took less than 5 ms to complete. Results might [...]
    
    Warning: Statistical outliers were detected. Consider [...]

  Summary
    'git log --no-walk --format=%h 1e59178e3f' ran
      1.01 ± 0.08 times faster than 'git show --no-patch --diff-merges=off --format=%h 1e59178e3f'
     14.98 ± 0.79 times faster than 'git show --no-patch --format=%h 1e59178e3f'