LukeMathWalker / LukeMathWalker/cargo-chef

Enable Link-Time Optimization (LTO)

Open
#287 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.7k
Forks
146
PR merge metrics
No merged PRs in 30d

Description

Hi!

I noticed that in the Cargo.toml file Link-Time Optimization (LTO) for the project is not enabled. I suggest switching it on since it will reduce the binary size (always a good thing to have) and will likely improve the application's performance a bit. If you want to read more about LTO, I recommend starting from this Rustc documentation.

I think you can enable LTO only for the Release builds so as not to sacrifice the developers' experience while working on the project since LTO consumes an additional amount of time to finish the compilation routine. If you think that a regular Release build should not be affected by such a change as well, then I suggest adding an additional dist or release-lto profile where in addition to regular release optimizations LTO will also be added. Such a change simplifies life for maintainers and others interested in the project persons who want to build the most optimized version of the application. If we enable it on the Cargo profile level, users, who install the application with cargo install will get the LTO-optimized version of the game "automatically". E.g., check cargo-outdated Release profile. You also could be interested in other optimization options like codegen-units = 1, etc.

Basically, it can be enabled with the following lines:

[profile.release]
lto = true

I have made quick tests (Fedora 41, Rust 1.82, the latest cargo-chef' version) by adding lto = true to the Release profile. The binary size reduction is from 6.2 Mib to 4.7 Mib.

Thank you.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Cargo.toml by reading the existing release profile and compare the LTO choices against the linked Rustc documentation. Decide whether LTO belongs in the regular release profile or a separate profile, then verify that the selected build produces the intended optimized binary without affecting development builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.