1
1
# Optimizations: the speed size tradeoff
2
2
3
3
Everyone wants their program to be super fast and super small but it's usually
4
- not possible to have maximize both characteristics. This section discusses the
5
- different optimization levels that ` rustc ` provides and how the affect the
4
+ not possible to have both characteristics. This section discusses the
5
+ different optimization levels that ` rustc ` provides and how they affect the
6
6
execution time and binary size of a program.
7
7
8
8
## No optimizations
@@ -25,15 +25,15 @@ debug = true
25
25
26
26
No optimizations is great for debugging because stepping through the code feels
27
27
like you are executing the program statement by statement, plus you can ` print `
28
- stack variables and function arguments in GDB. When the code is optimized trying
28
+ stack variables and function arguments in GDB. When the code is optimized, trying
29
29
to print variables results in ` $0 = <value optimized out> ` being printed.
30
30
31
31
The biggest downside of the ` dev ` profile is that the resulting binary will be
32
32
huge and slow. The size is usually more of a problem because unoptimized
33
33
binaries can occupy dozens of KiB of Flash, which your target device may not
34
34
have -- the result: your unoptimized binary doesn't fit in your device!
35
35
36
- Can we have smaller debugger friendly binaries? Yes, there's a trick.
36
+ Can we have smaller, debugger friendly binaries? Yes, there's a trick.
37
37
38
38
### Optimizing dependencies
39
39
@@ -117,7 +117,7 @@ profile which defaults to `opt-level = 3`.
117
117
118
118
Both ` opt-level = 2 ` and ` 3 ` optimize for speed at the expense of binary size,
119
119
but level ` 3 ` does more vectorization and inlining than level ` 2 ` . In
120
- particular, you'll see that at ` opt-level ` equal or greater than ` 2 ` LLVM will
120
+ particular, you'll see that at ` opt-level ` equal to or greater than ` 2 ` LLVM will
121
121
unroll loops. Loop unrolling has a rather high cost in terms of Flash / ROM
122
122
(e.g. from 26 bytes to 194 for a zero this array loop) but can also halve the
123
123
execution time given the right conditions (e.g. number of iterations is big
0 commit comments