diff --git a/Cargo.toml b/Cargo.toml index f34dbb8..2114f80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,23 @@ repository = "https://git.devcomp.xyz/DevComp/ssh-portfolio" authors = ["Erica Marigold "] build = "build.rs" +# Taken from https://github.com/microsoft/edit/blob/a3a6f5f/Cargo.toml#L20-L31 +# We use `opt-level = "s"` as it significantly reduces binary size. +# We could then use the `#[optimize(speed)]` attribute for spot optimizations. +# Unfortunately, that attribute currently doesn't work on intrinsics such as memset. +[profile.release] +codegen-units = 1 # Reduces binary size by ~2% +debug = "full" # No one needs an undebuggable release binary +lto = true # Reduces binary size by ~14% +opt-level = "s" # Reduces binary size by ~25% +split-debuginfo = "packed" # Generates a separate *.dwp/*.dSYM so the binary can get stripped +strip = "symbols" # See split-debuginfo - allows us to drop the size by ~65% + +[profile.dev] +opt-level = 2 # Optimize more than default, see https://github.com/RustCrypto/RSA/issues/144 +incremental = true # Improves re-compile times + [features] -# TODO: CLI feature default = ["blog"] blog = [ # Main deps @@ -28,9 +43,6 @@ blog = [ "dep:patch-crate" ] -[profile.dev] -opt-level = 2 - [package.metadata.patch] crates = ["ratatui-image"] diff --git a/src/app.rs b/src/app.rs index 8ff2ec1..c9c5584 100644 --- a/src/app.rs +++ b/src/app.rs @@ -107,6 +107,7 @@ impl App { }) } + #[optimize(speed)] pub async fn run( &mut self, term: Arc>, diff --git a/src/config.rs b/src/config.rs index c9bb90d..72534ca 100644 --- a/src/config.rs +++ b/src/config.rs @@ -131,6 +131,7 @@ fn project_directory() -> Option { ProjectDirs::from("xyz", "devcomp", env!("CARGO_PKG_NAME")) } +#[optimize(speed)] fn private_key_deserialize<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { diff --git a/src/main.rs b/src/main.rs index 8412769..d501e18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![feature(optimize_attribute)] + use std::net::SocketAddr; use clap::Parser as _; diff --git a/src/ssh.rs b/src/ssh.rs index a1d7da3..ee1265f 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -32,6 +32,7 @@ impl TermWriter { Self { session, channel, inner: CryptoVec::new() } } + #[optimize(speed)] fn flush_inner(&mut self) -> std::io::Result<()> { let handle = TokioHandle::current(); handle.block_on(async move { @@ -50,6 +51,7 @@ impl TermWriter { impl Write for TermWriter { #[instrument(skip(self, buf), level = "debug")] + #[optimize(speed)] fn write(&mut self, buf: &[u8]) -> std::io::Result { tracing::trace!("Writing {} bytes into SSH terminal writer buffer", buf.len()); self.inner.extend(buf); @@ -57,6 +59,7 @@ impl Write for TermWriter { } #[instrument(skip(self), level = "trace")] + #[optimize(speed)] fn flush(&mut self) -> std::io::Result<()> { tracing::trace!("Flushing SSH terminal writer buffer"); tokio::task::block_in_place(|| self.flush_inner()) diff --git a/src/tui/backend.rs b/src/tui/backend.rs index 1fbc62d..6d83bf5 100644 --- a/src/tui/backend.rs +++ b/src/tui/backend.rs @@ -35,6 +35,7 @@ impl Backend for SshBackend { Ok(Size { width: self.dims.0, height: self.dims.1 }) } + #[optimize(speed)] fn draw<'a, I>(&mut self, content: I) -> io::Result<()> where I: Iterator, { @@ -71,6 +72,7 @@ impl Backend for SshBackend { }) } + #[optimize(speed)] fn flush(&mut self) -> io::Result<()> { Backend::flush(&mut self.inner) } diff --git a/src/tui/mod.rs b/src/tui/mod.rs index 89dcc5a..ce576ff 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -111,6 +111,7 @@ impl Tui { }); } + #[optimize(speed)] async fn event_loop( status: Arc>, event_tx: UnboundedSender,