Skip to content

Enable Link-Time Optimization (LTO) and codegen-units = 1 for Release builds #4

@zamazan4ik

Description

@zamazan4ik

Hi!

Just found your project on the Rust subreddit :)

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 due to more aggressive compiler optimizations. If you want to read more about LTO and its possible modes, I recommend starting from this Rustc documentation. Additionally, codegen-units option can help too in a similar to LTO way, so I recommend to enable it as well.

I recommend enabling LTO only for Release builds so developers experience won't be affected by the increased build time. Actually, I can propose to use flags directly from the ripgrep profile.

Basically, it can be enabled with the following lines to the root Cargo.toml file:

[profile.release]
codegen-units = 1
lto = true # FullLTO - the most aggressive LTO version

I have made quick tests (AMD Ryzen 9 5900x, Fedora 43, Rust 1.91.1, the latest version of the project at the moment, cargo build --release command, without stripping) - here are the results:

  • Release (the current profile): 1.6 Mib, clean build time: 3s
  • Release + FullLTO + CU1: 1.3 Mib, clean build time: 9s

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions