11# Optimizations: the speed size tradeoff
22
33Everyone 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
66execution time and binary size of a program.
77
88## No optimizations
@@ -25,15 +25,15 @@ debug = true
2525
2626No optimizations is great for debugging because stepping through the code feels
2727like 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
2929to print variables results in ` $0 = <value optimized out> ` being printed.
3030
3131The biggest downside of the ` dev ` profile is that the resulting binary will be
3232huge and slow. The size is usually more of a problem because unoptimized
3333binaries can occupy dozens of KiB of Flash, which your target device may not
3434have -- the result: your unoptimized binary doesn't fit in your device!
3535
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.
3737
3838### Optimizing dependencies
3939
@@ -117,7 +117,7 @@ profile which defaults to `opt-level = 3`.
117117
118118Both ` opt-level = 2 ` and ` 3 ` optimize for speed at the expense of binary size,
119119but 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
121121unroll loops. Loop unrolling has a rather high cost in terms of Flash / ROM
122122(e.g. from 26 bytes to 194 for a zero this array loop) but can also halve the
123123execution time given the right conditions (e.g. number of iterations is big
0 commit comments