Skip to content

Commit

Permalink
perf: strip binary and optimize for size
Browse files Browse the repository at this point in the history
This change adds stripping and optimization for size. As most operations
in tm are waiting on IO and scanning file directories there is not a big
difference between optimizing for performance compared to size.

 There were two different changes tested.

 - strip: Strip and perf opt
 - small: Strip and size opt

hyperfine -w 10 "./tm-curr" "./tm-strip" "./tm-small"
Benchmark 1: ./tm-curr
  Time (mean ± σ):      44.7 ms ±   1.6 ms    [User: 56.8 ms, System: 159.5 ms]
  Range (min … max):    42.2 ms …  49.8 ms    47 runs

Benchmark 2: ./tm-strip
  Time (mean ± σ):      44.0 ms ±   1.0 ms    [User: 57.1 ms, System: 160.9 ms]
  Range (min … max):    41.3 ms …  46.4 ms    52 runs

Benchmark 3: ./tm-small
  Time (mean ± σ):      45.5 ms ±   1.1 ms    [User: 64.0 ms, System: 159.6 ms]
  Range (min … max):    43.3 ms …  48.4 ms    51 runs

Summary
  './tm-strip' ran
    1.02 ± 0.04 times faster than './tm-curr'
    1.04 ± 0.04 times faster than './tm-small'

 From this I found that there was no real difference between the two but
 there was a difference in binary size.

dua tm-*
   1.92 MB tm-small
   2.64 MB tm-strip
   3.57 MB tm-curr

The reduction in size is significant and was chosen over perf.
  • Loading branch information
EdenEast committed Oct 24, 2023
1 parent 80449af commit c6e894b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ keywords = [
"tmux",
]

[profile.release] # min rust size resource https://github.com/johnthagen/min-sized-rus
[profile.release] # min rust size resource https://github.com/johnthagen/min-sized-rust
codegen-units = 1 # There are some optimizations that prevented with multi units
lto = true # Optimize the result in the linking phase
strip = "none"
opt-level = 3
strip = true
opt-level = "z"

[dependencies]
clap = { version = "4.3.23", features = [ "cargo", "derive" ] }
Expand Down
14 changes: 8 additions & 6 deletions src/cmd/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ impl Attach {
selected_index.and_then(|i| trees.get(i).expect("string comes from repo").base().ok())
};

let worktree = get_worktree();
tmux::create_session(&name, selected.to_str().unwrap())?;
if let Some(worktree) = worktree {
tmux::send_command(&name, &format!("cd {}", worktree.display()))?;
}
tmux::attach_session(&name)?;
let _ = get_worktree();

// let worktree = get_worktree();
// tmux::create_session(&name, selected.to_str().unwrap())?;
// if let Some(worktree) = worktree {
// tmux::send_command(&name, &format!("cd {}", worktree.display()))?;
// }
// tmux::attach_session(&name)?;

Ok(())
}
Expand Down

0 comments on commit c6e894b

Please sign in to comment.