Experiencing a performance problem with Mercurial and want to dig deeper to learn what is making it so slow? This page is for you.

Profiling

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.

Showstack Extension

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.

Blackbox Logging

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.

Debug Output

Adding "--debug" to any command will enable low-level "debug" output. It is useful for getting more details on the progress of a command.

Traceback

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.

DebuggingPerformance (last edited 2015-10-23 21:19:12 by GregorySzorc)