Mercurial > hg
view rust/README.rst @ 46109:2f357d053df2
copies: make calculating lazy for dir move detection's "addedfiles"
The information calculated here was only needed if (a) --debug was specified, or
(b) a directory move was plausibly detected. With tree manifests (especially in
my pathological repo and with our custom setup), pre-calculating the `u1` and
`u2` can be quite slow, and it's not even necessary in many cases. Let's delay
calculating it until we know it's actually necessary. This should have no
observable differences in output.
### Performance
I ran a rebase command in my pathological repo, rebasing two nodes across
several public phase commits, but where no directory copies exist in any of the
paths I'm tracking.
#### Before
```
Time (mean ± σ): 3.711 s ± 0.061 s [User: 0.3 ms, System: 1.5 ms]
Range (min … max): 3.640 s … 3.827 s 10 runs
```
#### After
```
Time (mean ± σ): 868.3 ms ± 10.1 ms [User: 0.5 ms, System: 1.2 ms]
Range (min … max): 856.6 ms … 883.6 ms 10 runs
```
Differential Revision: https://phab.mercurial-scm.org/D9567
author | Kyle Lippincott <spectral@google.com> |
---|---|
date | Fri, 11 Dec 2020 13:39:56 -0800 |
parents | 7bd13bf99d1c |
children | ec14c37958ec |
line wrap: on
line source
=================== Mercurial Rust Code =================== This directory contains various Rust code for the Mercurial project. Rust is not required to use (or build) Mercurial, but using it improves performance in some areas. There are currently three independent rust projects: - chg. An implementation of chg, in rust instead of C. - hgcli. A project that provide a (mostly) self-contained "hg" binary, for ease of deployment and a bit of speed, using PyOxidizer. See hgcli/README.md. - hg-core (and hg-cpython): implementation of some functionality of mercurial in rust, e.g. ancestry computations in revision graphs, status or pull discovery. The top-level ``Cargo.toml`` file defines a workspace containing these crates. Using Rust code =============== Local use (you need to clean previous build artifacts if you have built without rust previously):: $ make PURE=--rust local # to use ./hg $ ./tests/run-tests.py --rust # to run all tests $ ./hg debuginstall | grep -i rust # to validate rust is in use checking Rust extensions (installed) checking module policy (rust+c-allow) If the environment variable ``HGWITHRUSTEXT=cpython`` is set, the Rust extension will be used by default unless ``--no-rust``. One day we may use this environment variable to switch to new experimental binding crates like a hypothetical ``HGWITHRUSTEXT=hpy``. Special features ================ You might want to check the `features` section in ``hg-cpython/Cargo.toml``. It may contain features that might be interesting to try out. To use features from the Makefile, use the `HG_RUST_FEATURES` environment variable: for instance `HG_RUST_FEATURES="some-feature other-feature"` Profiling ========= Setting the environment variable ``RUST_LOG=trace`` will make hg print a few high level rust-related performance numbers. It can also indicate why the rust code cannot be used (say, using lookarounds in hgignore). ``py-spy`` (https://github.com/benfred/py-spy) can be used to construct a single profile with rust functions and python functions (as opposed to ``hg --profile``, which attributes time spent in rust to some unlucky python code running shortly after the rust code, and as opposed to tools for native code like ``perf``, which attribute time to the python interpreter instead of python functions). Developing Rust =============== The current version of Rust in use is ``1.41.1``, because it's what Debian stable has. You can use ``rustup override set 1.41.1`` at the root of the repo to make it easier on you. Go to the ``hg-cpython`` folder:: $ cd rust/hg-cpython Or, only the ``hg-core`` folder. Be careful not to break compatibility:: $ cd rust/hg-core Simply run:: $ cargo build --release It is possible to build without ``--release``, but it is not recommended if performance is of any interest: there can be an order of magnitude of degradation when removing ``--release``. For faster builds, you may want to skip code generation:: $ cargo check For even faster typing:: $ cargo c You can run only the rust-specific tests (as opposed to tests of mercurial as a whole) with:: $ cargo test --all Formatting the code ------------------- We use ``rustfmt`` to keep the code formatted at all times. For now, we are using the nightly version because it has been stable enough and provides comment folding. To format the entire Rust workspace:: $ cargo +nightly fmt This requires you to have the nightly toolchain installed.