Optimizing production binaries
After we create the application, we want to prepare the application to accept a real connection. In software development, there's a production environment, also called a release environment or deployment environment. The production environment contains the configuration of the system and software to make it available to the intended customer. In Chapter 2, Building Our First Rocket Web Application, we learned that we can tell the Rust compiler to build release binary when compiling the Rust application. We can use cargo build
or cargo run
with the extra --release
flag.
To refresh, Cargo will read the configuration in Cargo.toml
in the [profile.release]
section. There are some compilation optimizations we can do to improve the resulting image:
- The first one is the number of
codegen-units
of compilation. Rust compilation can take significant time, and to solve this, the compiler may try to split it into parts and compile them in parallel...