Subject: bug#24126: vc-hg-state can be extremely slow

From: Jonathan Kotta <[email-masked]>
Date: Mon, 1 Aug 2016 13:40:36 -0500

Emacs uses `hg status -A` in vc-hg-state, which in turn is used in many vc
commands (e.g. vc-root-diff).  The "-A" option makes mercurial look at all
files under the directory, even the ignored ones.  If there are a lot of
ignored files, this will be very slow.

As an example, I have a repo that's 38MB / 300 files when freshly checked
out, and 34GB / 1.2M files when the build finishes (if you're curious, it's
a yocto project).  Without clearing the disk cache, `hg stat -A >
/dev/null` takes 28s; it's far longer if the disk cache isn't warmed up or
the output is actually used.  `hg status` takes about 90ms.

vg-git-state does not have this problem; currently it behaves like `hg
status`, i.e. honoring the ignore rules.   There is actually a FIXME
comment regarding this functionality, noting that `git ls-files -i -o
--exclude-standard` is the equivalent to `hg status -A`; this takes over
400s (I got sick of waiting).

I'm guessing VC has some sort of assumption that vc-x-state will return all
files.  Maybe the command could bailout after taking too long and use `hg
status`.  Maybe the command options could be configurable.  Personally, I'd
prefer just dropping the "-A", because I've never used it and I don't
really see why you'd want to get ignored files by default; this is my
current solution.

I'm using Emacs 24.5.1.  I've tested Emacs 25.1.1 and it still has the
issue; though vc-hg-state has changed, it still uses "-A" and is still very
slow on my repo.

-- 
Thanks,

Jonathan Kotta

Hofstadter's Law:
    It always takes longer than you expect, even
    when you take into account Hofstadter's Law.