Reducing the size of binaries

You may want to reduce the size of binaries. Often it's not necessary, but it may be useful if you have a distributed application that uses some hardware with limited space that requires tiny binaries. To reduce the size of your compiled application, you can use the strip command, which is part of the binutils package:

strip <path_to_your_binary>

For example, I tried to strip a compiled binary of the microservice we created in the Basic example section of this chapter. The binary with debugging symbols compiled with the cargo build command reduced from 79 MB to 12 MB. The version compiled with the --release flag reduced from 8.5 MB to 4.7 MB.

But remember that you can't debug a stripped binary, because the tool will remove all necessary information for debugging.

Sometimes, you may want to compare some ideas of optimizations and want to measure which one is better. You can use benchmarks for that. Let's look at the benchmark feature supplied with cargo.

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

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