hg wip is slow af

My day job at Mozilla involves interacting with a large mercurial repository and keeping track of multiple chunks of work. I use a workflow that involves having a chain of commits per bug that I’m working on, with each chain descending from the current mozilla-central tip.

In order to quickly take a look at the state of my repository – i.e., the different bugs that I’m currently working on, which commit is currently selected in the working directory, etc. – I use the hg wip command, about which you can learn more here. This is pretty awesome, but it has one drawback for me: it’s SLOW AS FUCK.

To quantify the slowness for the sake of this blog post, I very scientifically time‘d hg wip a few times, and the fastest run was 1.4s. When you’re quickly iterating on a patch, this is BAD. For one line changes, making the change probably took less time than running hg wip.

Here’s my solution: cache the output of hg wip. The effect of this should be that hg wip is an instantaneous command (it should just dump a cached output), with the side effect that it might provide out-of-date information. In practice, this side effect does not bother me much. Here’s how I implemented caching:

In ~/.hgrc:

wwip = log --graph --rev=wip --template=wip
wip = !tput rmam; cat ./.___WIP___ || $HG wwip; tput smam

In words, this basically remaps the original wip command to wwip, and makes wip dump a file, .___WIP___. Where does this come from? The answer is an addition to my .bash_profile:

hg() {
 command hg --pager=no "$@";
 (bash -c "unbuffer command hg --pager=no wwip > $temp_file_wip; mv $temp_file_wip ./.___WIP___;" &);
 return 1;

Boom. This acts as a proxy for hg: it transparently captures hg commands, runs them, but also (atomically) dumps hg wwip into the .___WIP___ file in the background, for future snappy hg wip runs.


PS: I do have fsmonitor enabled, but either I have unreasonable expectations from it or all my efforts to set it up and get it working correctly with my m-c clone have been futile.

Leave a Reply

Your email address will not be published.