posit-dev / posit-dev/air

Enable Link-Time Optimization (LTO) and codegen-units = 1

Open
#211 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
446
Forks
32
Avg merge
16h 48m
Merged PRs (30d)
1

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. If you want to read more about LTO and its possible modes, 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. In this case, we can create a dedicated [profile.optimized-dev] profile where LTO will be disabled (so developers experience will not be affected). If we enable it on the Cargo profile level for the Release profile, users, who install the application with cargo install, will get the LTO-optimized version of the app "automatically". E.g., check cargo-outdated Release profile. You also could be interested in other optimization options like codegen-units = 1 - it also brings improvements over the current defaults.

Basically, it can be enabled with the following lines:

[profile.release]
codegen-units = 1
lto = true

If we enable it for the Release profile, according to the current scripts it will automatically be applied to the Dist profile as well.

I have made quick tests (AMD Ryzen 5900x, Fedora 41, Rust 1.84.1, the latest version of the project at the moment, cargo build --profile dist --workspace command) - here are the results:

  • Dist (current default): 12 MiB, clean build time: 59s (UPD: the right clean build time is about 35s)
  • Dist + codegen-units = 1 + Fat LTO: 8 MiB, clean build time: 70s

Thank you.

Contributor guide

Open the contributing guide

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 reviewing the release and dist profiles, then run the mentioned cargo build --profile dist --workspace command to establish current size and build time. Enable the agreed optimization settings for release builds and verify the resulting binary size and compilation impact against the reported measurements.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.