22
33There are multiple additional build configuration options and techniques that can be used to compile a
44build of ` rustc ` that is as optimized as possible (for example when building ` rustc ` for a Linux
5- distribution). The status of these configuration options for various Rust targets is tracked [ here] .
5+ distribution).
6+ The status of these configuration options for various Rust targets is tracked [ here] .
67This page describes how you can use these approaches when building ` rustc ` yourself.
78
89[ here ] : https://github.com/rust-lang/rust/issues/103595
910
1011## Link-time optimization
1112
12- Link-time optimization is a powerful compiler technique that can increase program performance. To
13- enable (Thin-)LTO when building ` rustc ` , set the ` rust.lto ` config option to ` "thin" `
13+ Link-time optimization is a powerful compiler technique that can increase program performance.
14+ To enable (Thin-)LTO when building ` rustc ` , set the ` rust.lto ` config option to ` "thin" `
1415in ` bootstrap.toml ` :
1516
1617``` toml
@@ -29,8 +30,8 @@ Enabling LTO on Linux has [produced] speed-ups by up to 10%.
2930
3031## Memory allocator
3132
32- Using a different memory allocator for ` rustc ` can provide significant performance benefits. If you
33- want to enable the ` jemalloc ` allocator, you can set the ` rust.jemalloc ` option to ` true `
33+ Using a different memory allocator for ` rustc ` can provide significant performance benefits.
34+ If you want to enable the ` jemalloc ` allocator, you can set the ` rust.jemalloc ` option to ` true `
3435in ` bootstrap.toml ` :
3536
3637``` toml
@@ -53,7 +54,8 @@ rust.codegen-units-std = 1
5354## Instruction set
5455
5556By default, ` rustc ` is compiled for a generic (and conservative) instruction set architecture
56- (depending on the selected target), to make it support as many CPUs as possible. If you want to
57+ (depending on the selected target), to make it support as many CPUs as possible.
58+ If you want to
5759compile ` rustc ` for a specific instruction set architecture, you can set the ` target_cpu ` compiler
5860option in ` RUSTFLAGS ` :
5961
@@ -72,14 +74,16 @@ llvm.cflags = "-march=x86-64-v3"
7274## Profile-guided optimization
7375
7476Applying profile-guided optimizations (or more generally, feedback-directed optimizations) can
75- produce a large increase to ` rustc ` performance, by up to 15% ([ 1] , [ 2] ). However, these techniques
77+ produce a large increase to ` rustc ` performance, by up to 15% ([ 1] , [ 2] ).
78+ However, these techniques
7679are not simply enabled by a configuration option, but rather they require a complex build workflow
7780that compiles ` rustc ` multiple times and profiles it on selected benchmarks.
7881
7982There is a tool called ` opt-dist ` that is used to optimize ` rustc ` with [ PGO] (profile-guided
80- optimizations) and [ BOLT] (a post-link binary optimizer) for builds distributed to end users. You
81- can examine the tool, which is located in ` src/tools/opt-dist ` , and build a custom PGO build
82- workflow based on it, or try to use it directly. Note that the tool is currently quite hardcoded to
83+ optimizations) and [ BOLT] (a post-link binary optimizer) for builds distributed to end users.
84+ You can examine the tool, which is located in ` src/tools/opt-dist ` , and build a custom PGO build
85+ workflow based on it, or try to use it directly.
86+ Note that the tool is currently quite hardcoded to
8387the way we use it in Rust's continuous integration workflows, and it might require some custom
8488changes to make it work in a different environment.
8589
@@ -93,9 +97,9 @@ changes to make it work in a different environment.
9397To use the tool, you will need to provide some external dependencies:
9498
9599- A Python3 interpreter (for executing ` x.py ` ).
96- - Compiled LLVM toolchain, with the ` llvm-profdata ` binary. Optionally, if you want to use BOLT,
97- the ` llvm-bolt ` and
98- ` merge-fdata ` binaries have to be available in the toolchain.
100+ - Compiled LLVM toolchain, with the ` llvm-profdata ` binary.
101+ Optionally, if you want to use BOLT,
102+ the ` llvm-bolt ` and ` merge-fdata ` binaries have to be available in the toolchain.
99103
100104These dependencies are provided to ` opt-dist ` by an implementation of the [ ` Environment ` ] struct.
101105It specifies directories where will the PGO/BOLT pipeline take place, and also external dependencies
0 commit comments