Skip to content

Commit 5940262

Browse files
committed
Reword with focus on trade-offs
1 parent 79f56d5 commit 5940262

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

src/doc/src/guide/build-performance.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
# Optimizing Build Performance
22

3-
Compilation of Rust crates can sometimes be rather slow, due to various reasons (such as the used compilation model and the design of the Rust language and its compiler). There are various approaches that can be used to optimize build performance, which mostly fall under two categories:
3+
Cargo uses configuration defaults that try to balance various aspects, including debuggability, runtime performance, build performance, binary size and others. Because of that, build performance is sometimes traded off for other benefits which may not be as important for your circumstances. This guide will step you through changes you can make to improve build performance.
44

5-
- Modify compiler or Cargo flags
6-
- Modify the source code of your crate(s)
5+
Same as when optimizing runtime performance, be sure to measure these changes against the workflows you actually care about, as we provide general guidelines and your circumstances may be different.
76

8-
This guide focuses on the first approach.
7+
Example workflows to consider include:
8+
- Compiler feedback as you develop (`cargo check` after making a code change)
9+
- Test feedback as you develop (`cargo test` after making a code change)
10+
- CI builds
911

10-
Below, you can find several methods that can be used to optimize build performance. It is important to note that their effect varies a lot based on the compiled crate, and in some cases they can actually make compilation slower. You should always measure build performance on your crate(s) to determine if a given method described here is effective for your crate.
11-
12-
Note that some of these approaches currently require using the nightly toolchain.
12+
Note that some approaches described below currently require using the nightly toolchain.
1313

1414
## Reduce amount of generated debug information
1515

16-
By default, the `dev` [profile](../reference/profiles.md) enables generation of full debug information (debuginfo) both for local crates and also for all dependencies. This is useful if you want to debug your code with a debugger or profile it with a profiler, but it can also have a significant compilation and linking time cost.
17-
18-
You can reduce that cost by reducing the amount of debuginfo that is generated. The fastest option is `debug = false`, which completely turns off debuginfo generation, but a reasonable trade-off could also be setting `debug = "line-tables-only"`, which only generates enough debuginfo to support proper source code links in backtraces, which are generated e.g. when a panic happens.
16+
Recommendation: Add to your `Cargo.toml` (for maintainers) or `$CARGO_HOME/.cargo/config.toml` (for contributors):
1917

20-
Here is an example of configuring debuginfo generation in `Cargo.toml`:
2118
```toml
2219
[profile.dev]
23-
debug = false # or "line-tables-only"
24-
```
25-
26-
If you want to keep debuginfo for your crate only, but you do not need it for your dependencies, you can set `debug = false` as the default value for a given profile, and then enable debuginfo only for your crate:
20+
debug = "line-tables-only"
2721

28-
```toml
29-
[profile.dev]
22+
[profile.dev.package."*"]
3023
debug = false
3124

32-
[profile.dev.package]
33-
<your-crate-name>.debug = true
25+
[profile.debugging]
26+
inherits = "dev"
27+
debug = true
3428
```
3529

30+
This will:
31+
- Change the [`dev` profile](../reference/profiles.md#dev) (default for development commands) to:
32+
- Limit [debug information](../reference/profiles.md#debug) for workspace members to what is needed for useful panic backtraces
33+
- Avoid generating any debug information for dependencies
34+
- Provide an opt-in for when debugging via [`--profile debugging`](../reference/profiles.md#custom-profiles)
35+
36+
Trade-offs:
37+
- ✅ Faster per-crate build times
38+
- ✅ Faster link times
39+
- ✅ Smaller disk usage of the `target` directory
40+
- ❌ Requires a full rebuild to have a high-quality debugger experience
41+
3642
## Use an alternative codegen backend
3743

3844
> **This requires nightly/unstable features**

0 commit comments

Comments
 (0)