From 487524c0224cb117dfd151ad9976ce539702639c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 8 Nov 2021 14:19:02 -0500 Subject: [PATCH] Tune the 'profile.release' options for a smaller compile size. By enabling link-time optimization, setting 'opt-level=s', and setting compilation-units=1, we can get a much smaller download size, which is one of our objectives. Making these changes reduces the binary size for me (on x86_64) by about 42%. If you also run "strip --strip-debug" on the resulting binary, the resulting size is 55% smaller than the original binary size. These effects persist if you compress the binary. Supposing that we use xz compression, these options make save 32% of compressed binary size. If we also "strip --strip-debug" before compressing, the compressed binary saves 43% from the original binary size. With all of these options applied, on x86_64 linux with xz compression, we're at a nice 1.5 MiB download. If we statically link to openssl and sqlite, we're still only at a 2.8 MiB download. There is a build time cost to these changes: for me, it comes to a 10%-25% build time increase. This is part of arti#172. --- Cargo.toml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c4f0138d..b1d2534c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,4 +34,23 @@ members = [ "crates/arti" ] -resolver = "2" \ No newline at end of file +resolver = "2" + +[profile.release] +# By default we'd like to get good performance and a small download size. +# (Assuming xz compression on the binary.) +# +# The biggest win is to run `strip --strip-debug` on the binary after +# generating it, to through out debugging symbols that we inherited from +# other libraries. Don't do `strip --strip-unused`, though, or you'll +# break backtraces. That saves about 21% download size. + +# Using LTO saves a further 14% of download size, and improves performance, +# at the cost of compile time. +lto = true +# Setting codegen-units=1 saves a further 7% download size. It also +# improves performance at the cost of compile time. +codegen-units = 1 +# Optimize for size. [Actually this is even smaller than 'z' on rust +# 1.56. It saves about 11% download size over the default value of '3'.] +opt-level = 's' -- GitLab