Link-time optimizations

The compiler does a lot of optimizations automatically during the compilation process, but we can also activate some optimizations after the sources compiled. This technique called Link Time Optimizations (LTO) and applied after code linked and the whole program available. You can activate this optimization for Rust program by adding an extra section to the Cargo.toml file in your project:

[profile.release]
lto = true

If you have already compiled the project with this optimization, force a complete rebuild of your project. But this option also takes much more time for compilation. This optimization does not necessarily improve the performance, but can help to reduce the size of a binary.

If you activate all optimization options, it doesn't mean you have made the fastest version of an application. Too many optimizations can reduce the performance of a program and you should compare the results with an original version. Most often, just using the standard --release helps the compiler to produces a binary with an optimal balance of compilation speed and performance.

Normal Rust programs use panic macros for unhandled errors and print backtraces. For optimization, you can consider turning this off. Let's look at this technique in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.98.250