##// END OF EJS Templates
rust: add a pointer for profiling to the README...
Valentin Gatien-Baron -
r45440:7ca1d635 default
parent child Browse files
Show More
@@ -1,84 +1,99 b''
1 ===================
1 ===================
2 Mercurial Rust Code
2 Mercurial Rust Code
3 ===================
3 ===================
4
4
5 This directory contains various Rust code for the Mercurial project.
5 This directory contains various Rust code for the Mercurial project.
6 Rust is not required to use (or build) Mercurial, but using it
6 Rust is not required to use (or build) Mercurial, but using it
7 improves performance in some areas.
7 improves performance in some areas.
8
8
9 There are currently three independent rust projects:
9 There are currently three independent rust projects:
10 - chg. An implementation of chg, in rust instead of C.
10 - chg. An implementation of chg, in rust instead of C.
11 - hgcli. A project that provide a (mostly) self-contained "hg" binary,
11 - hgcli. A project that provide a (mostly) self-contained "hg" binary,
12 for ease of deployment and a bit of speed, using PyOxidizer. See
12 for ease of deployment and a bit of speed, using PyOxidizer. See
13 hgcli/README.md.
13 hgcli/README.md.
14 - hg-core (and hg-cpython): implementation of some
14 - hg-core (and hg-cpython): implementation of some
15 functionality of mercurial in rust, e.g. ancestry computations in
15 functionality of mercurial in rust, e.g. ancestry computations in
16 revision graphs, status or pull discovery. The top-level ``Cargo.toml`` file
16 revision graphs, status or pull discovery. The top-level ``Cargo.toml`` file
17 defines a workspace containing these crates.
17 defines a workspace containing these crates.
18
18
19 Using Rust code
19 Using Rust code
20 ===============
20 ===============
21
21
22 Local use (you need to clean previous build artifacts if you have
22 Local use (you need to clean previous build artifacts if you have
23 built without rust previously)::
23 built without rust previously)::
24
24
25 $ make PURE=--rust local # to use ./hg
25 $ make PURE=--rust local # to use ./hg
26 $ ./tests/run-tests.py --rust # to run all tests
26 $ ./tests/run-tests.py --rust # to run all tests
27 $ ./hg debuginstall | grep -i rust # to validate rust is in use
27 $ ./hg debuginstall | grep -i rust # to validate rust is in use
28 checking Rust extensions (installed)
28 checking Rust extensions (installed)
29 checking module policy (rust+c-allow)
29 checking module policy (rust+c-allow)
30
30
31 If the environment variable ``HGWITHRUSTEXT=cpython`` is set, the Rust
31 If the environment variable ``HGWITHRUSTEXT=cpython`` is set, the Rust
32 extension will be used by default unless ``--no-rust``.
32 extension will be used by default unless ``--no-rust``.
33
33
34 One day we may use this environment variable to switch to new experimental
34 One day we may use this environment variable to switch to new experimental
35 binding crates like a hypothetical ``HGWITHRUSTEXT=hpy``.
35 binding crates like a hypothetical ``HGWITHRUSTEXT=hpy``.
36
36
37 Profiling
38 =========
39
40 Setting the environment variable ``RUST_LOG=trace`` will make hg print
41 a few high level rust-related performance numbers. It can also
42 indicate why the rust code cannot be used (say, using lookarounds in
43 hgignore).
44
45 ``py-spy`` (https://github.com/benfred/py-spy) can be used to
46 construct a single profile with rust functions and python functions
47 (as opposed to ``hg --profile``, which attributes time spent in rust
48 to some unlucky python code running shortly after the rust code, and
49 as opposed to tools for native code like ``perf``, which attribute
50 time to the python interpreter instead of python functions).
51
37 Developing Rust
52 Developing Rust
38 ===============
53 ===============
39
54
40 The current version of Rust in use is ``1.34.2``, because it's what Debian
55 The current version of Rust in use is ``1.34.2``, because it's what Debian
41 stable has. You can use ``rustup override set 1.34.2`` at the root of the repo
56 stable has. You can use ``rustup override set 1.34.2`` at the root of the repo
42 to make it easier on you.
57 to make it easier on you.
43
58
44 Go to the ``hg-cpython`` folder::
59 Go to the ``hg-cpython`` folder::
45
60
46 $ cd rust/hg-cpython
61 $ cd rust/hg-cpython
47
62
48 Or, only the ``hg-core`` folder. Be careful not to break compatibility::
63 Or, only the ``hg-core`` folder. Be careful not to break compatibility::
49
64
50 $ cd rust/hg-core
65 $ cd rust/hg-core
51
66
52 Simply run::
67 Simply run::
53
68
54 $ cargo build --release
69 $ cargo build --release
55
70
56 It is possible to build without ``--release``, but it is not
71 It is possible to build without ``--release``, but it is not
57 recommended if performance is of any interest: there can be an order
72 recommended if performance is of any interest: there can be an order
58 of magnitude of degradation when removing ``--release``.
73 of magnitude of degradation when removing ``--release``.
59
74
60 For faster builds, you may want to skip code generation::
75 For faster builds, you may want to skip code generation::
61
76
62 $ cargo check
77 $ cargo check
63
78
64 For even faster typing::
79 For even faster typing::
65
80
66 $ cargo c
81 $ cargo c
67
82
68 You can run only the rust-specific tests (as opposed to tests of
83 You can run only the rust-specific tests (as opposed to tests of
69 mercurial as a whole) with::
84 mercurial as a whole) with::
70
85
71 $ cargo test --all
86 $ cargo test --all
72
87
73 Formatting the code
88 Formatting the code
74 -------------------
89 -------------------
75
90
76 We use ``rustfmt`` to keep the code formatted at all times. For now, we are
91 We use ``rustfmt`` to keep the code formatted at all times. For now, we are
77 using the nightly version because it has been stable enough and provides
92 using the nightly version because it has been stable enough and provides
78 comment folding.
93 comment folding.
79
94
80 To format the entire Rust workspace::
95 To format the entire Rust workspace::
81
96
82 $ cargo +nightly fmt
97 $ cargo +nightly fmt
83
98
84 This requires you to have the nightly toolchain installed.
99 This requires you to have the nightly toolchain installed.
General Comments 0
You need to be logged in to leave comments. Login now