Skip to content

Consider enabling more aggressive optimizations for the Dist profile: Fat LTO and codegen-units = 1 #501

Open
@zamazan4ik

Description

@zamazan4ik

Hi!

I see that the project already uses ThinLTO in the Dist profile in the root Cargo.toml file. However, ThinLTO is usually less efficient from the perspective of performed optimizations than Fat (aka Full) LTO, and cargo-dist defaults are not the most optimal by default. Additionally, I suggest enabling codegen-units = 1 (CG1) too. Enabling more advanced optimizations allows us to reduce the binary size further (always a good thing) and improve the application performance more.

Basically, it can be enabled with the following change:

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

I have made quick local tests (AMD Ryzen 9 5900x, Fedora 42, Rust 1.86, the latest version of this project at the moment, cargo build --profile dist command) - the results are below.

  • ThinLTO (current Dist profile): 82 Mib, clean build time: 2m 15s
  • FatLTO + codegen-units = 1: 65 Mib, clean build time: 4m 42s

Since the Dist profile is used only for release binaries, this build time increase shouldn't be a problem for the project.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions