From fbb307551de0d26e612d1b00f386ccf45d84b066 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Mon, 7 Jan 2019 13:59:08 -0800 Subject: Switch to using the system allocator In the past we have already taken a couple of steps to reduce the size of the final binary, arguing that binary size is the metric of most relevance for the program at hand: - the memory footprint is close to irrelevant because the program does not stay resident in memory for long - execution speed is likely dominated by communication with the Nitrokey itself, which is a slow I/O device With that in mind, this change decreases the binary size further by swapping the default allocator we use (typically jemalloc) with the system allocator (which is malloc based on Unix systems). Given that we are by no means allocation sensitive, there is no point in wasting binary size on something that adds no value. This change decreases the binary size by another 324 KiB (for an already stripped release mode binary). --- nitrocli/CHANGELOG.md | 5 +++++ nitrocli/src/main.rs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/nitrocli/CHANGELOG.md b/nitrocli/CHANGELOG.md index 396e966..6236a77 100644 --- a/nitrocli/CHANGELOG.md +++ b/nitrocli/CHANGELOG.md @@ -1,3 +1,8 @@ +Unreleased +---------- +- Further decreased binary size by using system allocator + + 0.2.2 ----- - Added the `-v`/`--verbose` option to control libnitrokey log level diff --git a/nitrocli/src/main.rs b/nitrocli/src/main.rs index 9a4216a..8d5953b 100644 --- a/nitrocli/src/main.rs +++ b/nitrocli/src/main.rs @@ -80,6 +80,7 @@ mod pinentry; #[cfg(test)] mod tests; +use std::alloc; use std::env; use std::ffi; use std::io; @@ -88,6 +89,13 @@ use std::result; use crate::error::Error; +// Switch from the default allocator (typically jemalloc) to the system +// allocator (malloc based on Unix systems). Our application is by no +// means allocation intensive and the default allocator is typically +// much larger in size, causing binary bloat. +#[global_allocator] +static A: alloc::System = alloc::System; + type Result = result::Result; const NITROCLI_ADMIN_PIN: &str = "NITROCLI_ADMIN_PIN"; -- cgit v1.2.3