Experiencing a performance problem with Mercurial and want to dig deeper to learn what is making it so slow? This page is for you.
Adding --profile to any Mercurial command will run Mercurial with the Python profiler enabled and will print a table of times after command execution. This can be used to see what functions Mercurial is spending most of its time in.
By default, the lsprof profiler (used by cProfile) is used. This profiler traces every function call and can add significant overhead. It is not uncommon for execution to slow down 2-3x. Alternatively, the statprof sampling profiler can be used. Activate it by running with environment variable HGPROF=stat or by setting an appropriate hgrc option to make it the default.
See "hg help config.profiling" for config options that control profiling behavior, including ways to output results in ways that can be consumed by tools like kcachegrind.
When installed, the showstack extension will print a stack when ctrl+\ or ctrl+t is pressed. This is useful for seeing what Mercurial is doing at any given instant. This is useful for debugging hangs or long pauses.
The blackbox extension (hg help -e blackbox) will enable logging of additional forensic data to .hg/blackbox.log. This often contains additional timing data that isn't otherwise printed.
Adding "--debug" to any command will enable low-level "debug" output. It is useful for getting more details on the progress of a command.
Running any command with "--traceback" will print a stack when ctrl+c is pressed. This allows you to see what Mercurial was doing at the time the command was killed. It can be useful for debugging hangs. But the aforementioned showstack extension is almost always a better tool.