aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2018-12-29 09:55:11 -0800
committerDaniel Mueller <deso@posteo.net>2018-12-29 09:55:11 -0800
commit175f321e822308839d2a4d7ae89437cd29945e65 (patch)
tree1385c25412153d00bbcdcdcdb481df06ef48ba27
parent32c22bd1eb9fe05db30cf1062d089b21bd00c3a7 (diff)
downloadnitrocli-175f321e822308839d2a4d7ae89437cd29945e65.tar.gz
nitrocli-175f321e822308839d2a4d7ae89437cd29945e65.tar.bz2
Enable LTO and more optimizations for release builds
The program's binary is more than 1,5 MiB in size (after stripping debug symbols). Although in general that is not a size to worry about, keeping a small binary and memory footprint is beneficial in the majority of cases and leaves a tangentially better impression with users. To that end, this change enables the following optimizations to be performed when creating a release build: 1) We compile with optimization for code size. We have no performance sensitive code and are communicating with a slow I/O device to begin with, meaning that binary size will ultimately have the most weight when judging the program. Hence, minimizing it seems like the best trade-off. 2) We enable link-time optimization (LTO). At the expense of compilation time (which is not a concern for what may almost be considered a one-off operation), this step can reduce binary size by eliminating more unused code as well as enable performance related optimizations not possible without this setting. For similar reasons we disable incremental builds and treat the entire compilation as one unit. The end result of these optimizations is a reduction of binary size by almost a fourth (420 KiB). Those optimizations come at little to no cost (depending on one's view). There is another one that we could enable and that is to abort on panics instead of unwinding, yielding savings of 44 KiB. However, we refrained from doing so because that has a negative impact on the amount of error reporting happening in case of a panic.
-rw-r--r--nitrocli/CHANGELOG.md1
-rw-r--r--nitrocli/Cargo.toml6
2 files changed, 7 insertions, 0 deletions
diff --git a/nitrocli/CHANGELOG.md b/nitrocli/CHANGELOG.md
index 2bc16a9..09ac0eb 100644
--- a/nitrocli/CHANGELOG.md
+++ b/nitrocli/CHANGELOG.md
@@ -2,6 +2,7 @@ Unreleased
----------
- Added the `pws` command for accessing the password safe
- Added the `lock` command for locking the Nitrokey device
+- Adjusted release build compile options to optimize binary for size
0.2.0
diff --git a/nitrocli/Cargo.toml b/nitrocli/Cargo.toml
index ff3034a..9a692e4 100644
--- a/nitrocli/Cargo.toml
+++ b/nitrocli/Cargo.toml
@@ -35,6 +35,12 @@ A command line tool for interacting with the Nitrokey Storage device.
[badges]
gitlab = { repository = "d-e-s-o/nitrocli", branch = "master" }
+[profile.release]
+opt-level = "z"
+lto = true
+codegen-units = 1
+incremental = false
+
[dependencies.argparse]
version = "0.2.2"
path = "../argparse"