tg-summary: the last of the great speed-ups
commitf7f852d1d06c7a66bccf2979c4383e4048bf3671
authorKyle J. McKay <mackyle@gmail.com>
Mon, 19 Jun 2017 06:18:28 +0000 (18 23:18 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Mon, 19 Jun 2017 06:18:28 +0000 (18 23:18 -0700)
tree1da399c19de593eda580024cc36d623df0bf882b
parent4ff7e86c51fb9504dec2841dfb62f23fec61ebcd
tg-summary: the last of the great speed-ups

Make full use of the recurse deps functionality provided by
awk and implement a new "needs_update_check" function that
most efficiently collects "needs update" information.

The result being particularly suitable for use with
tg summary at the expense of being unsuitable for use by
tg update (which continues to use the original "needs_update"
function).

Although some of this change could have been accomplished
pre-awk, the resulting speed increase would not have been as
dramatic as the "annihilated" and "has remote" checks come for
free with the awk version.

Additionally the speed-up would have been less apparent with
the pre-awk slow message display.

As an illustration of the substantial speedup tg summary has
undergone, here are some benchmarks for a `tg summary` of all
the branches in a rather complicated TopGit repository.

For each line the TopGit version is shown along with two times
(in minutes:seconds), the first being run on a pristine checkout
and the second being run immediately thereafter to show any
caching effects:

TopGit version|First /Second| Comments
--------------|-------------|----------------------------------
topgit-0.16   | 4:41 / 4:41 | no caching at all, 4+ minutes!
topgit-0.17   | 0:47 / 0:47 | better recurse_deps, no caching
topgit-0.18   | 0:41 / 0:18 | now with caching
topgit-0.19   | 0:42 / 0:18 | basically the same
topgit-0.19.1 | 0:42 / 0:19 | basically the same
topgit-0.19.2 | 0:43 / 0:18 | basically the same
topgit-0.19.3 | 0:42 / 0:18 | basically the same
topgit-0.19.4 | 0:43 / 0:19 | basically the same
topgit-0.19.5 | 0:43 / 0:19 | basically the same
topgit-0.19.6 | 0:43 / 0:19 | basically the same
topgit-0.19.7 | 0:25 / 0:10 | awk to the rescue
topgit-0.19.8 | 0:17 / 0:03 | maximum awk (this commit)

Compared to the topgit-0.16 release, with these changes
the result is approximately 16.4 times faster before the
cache has been built and a whopping 93.3 times faster after
it's been built.  Since the cache is maintained by normal
TopGit activities it's unusual for it to be completely
unusable.  Therefore the two orders of magnitutde speed-up
should be the norm not the exception.

The limiting factor at this point is really the underlying
Git operations and there's not really any way to batch up the
"is empty branch" or "branch contains" operations, but the
previous result can be cached and reused if the refs have not
changed (which is what the cache accomplishes).

Therefore it's unlikely there will be any more abrupt speed-ups
seen for the tg summary command after this.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
tg-summary.sh
tg.sh