gg2 is a command line tool for doing things with Git branches, faster. One of the convenient commands is gg2 branches.
It lists your recent branches, sorted by committer-date and for each branch it displays a human-friendly date distance and whether it's already been merged. Looks like this:
Turns out, for large repos figuring out which branches have already been merged is quite slow. For example, in this repo it takes half a second to list all merged branches:
$ git branch --all --merged | wc -l
669
$ time git branch --all --merged 1>/dev/null
real 0m0.490s
user 0m0.460s
sys 0m0.030s
The problem was that gg2 branches also does multiple other git branch listing commands to get information. In particular: get the current branch, figure out the default branch, a list of branch committer dates, and a list of merged branches.
All of these async operations were done in serial. With a bit of rearranging, and refactoring, all of these can be turned into this:
const [defaultBranch, currentBranch, dates, isMerged] = await Promise.all([
getDefaultBranch(git),
getCurrentBranch(git),
getAllBranchDates(git),
getAllMergedBranches(git),
])
The getAllMergedBranches(git) function still takes a very long time and I think it lists all remote branches that have been merged. Anyway, now it's only the slowest part of the Promise.all rather than one of multiple.

Comments