Skip to content

Enable Link-Time Optimization (LTO) for Release builds #75

@zamazan4ik

Description

@zamazan4ik

Is your feature request related to a problem? Please describe.
It's not a problem - it's an improvement idea. Improvement from the binary size and performance perspectives

Describe the solution you'd like
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 a bit more about LTO, I can recommend starting from this Rustc documentation.

I suggest enabling 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 performant version of the package. Using ThinLTO should also help to reduce the build-time overhead with LTO - full LTO during my local tests consumed at peak 11 Gib RAM. If we enable it on the Cargo profile level, users, who build the package manually will get the LTO-optimized version "automatically". E.g., check cargo-outdated Release profile.

Basically, it can be enabled with the following lines:

[profile.release]
lto = true

According to my local tests (the latest pathway at the moment, Fedora 41, Rustc 1.83), with the command maturin build --release --strip I got the resulting wheel size reduction from 50 Mib to 43 Mib. I didn't perform performance benchmarks (at least not yet) but expect at least the same performance level (however, the CPU part of the performance should be improved as well).

Describe alternatives you've considered
N/A

Additional context
N/A

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions