Skip to content

Optimizations

Ondřej Perutka edited this page Oct 17, 2019 · 7 revisions

As the Arrow Client is intended to be used in embedded systems, we understand your need for making it as much resource efficient as possible. Using Rust as a language for the reference implementation may not look like a step in this direction (mainly in terms of memory consumption); however, we made this choice because of numerous other benefits we get from using Rust. The most important one in comparison with C or C++ is guaranteed memory safety. This document will provide you with some useful tips on creating smaller executables.

Compile time options

  1. Use the --release option (this will strip away all debug symbols and it will also enable code optimizations).
  2. Do not use the --features discovery option unless you want to use the network scanning feature.

If you want to generate as small executable as possible, use the following command:

cargo build --release

Currently, the size of the resulting binary will be around 1.7 MB for ARM. This may be still huge for many devices. We recommend stripping the binary of all remaining symbols.

Stripping the binary

After compilation, you can do even more to make the binary smaller. You can strip away all remaining symbols using:

strip -s arrow-client

This step will reduce the size of the binary to ~570 kB (!!!) without any additional costs.

Compressing the binary

Supposing 570 kB is still too much for you, you can make a compressed binary. There are basically two options. Both of them will cost you some RAM. The first option is using gzexe:

gzexe arrow-client

This will create a shell script with embedded binary data (the compressed executable). The size of the file will be ~300 kB. In order to run such application, your system will need a shell and gzip for decompressing the executable. The executable will be decompressed into a temporary file which will be deleted soon after the application is started. However, the shell process will run together with the application the whole time. The shell process will be idle, so it will not consume any CPU time, but it requires some extra RAM. Depending on your system, the amount of required extra memory may vary between units and a few hundreds of kB.

The second option is using upx:

upx -9 arrow-client

This command will create a self-contained compressed executable. The size of the executable will be ~290 kB. The application will need to allocate an extra block of memory where the inner executable will be decompressed. The amount of required extra memory will be around 600 kB.