Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zamazan4ik opened this issue Nov 30, 2024 · 2 comments
Open

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

zamazan4ik opened this issue Nov 30, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@zamazan4ik
Copy link

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

@zamazan4ik zamazan4ik added the enhancement New feature or request label Nov 30, 2024
@dxtrous
Copy link
Member

dxtrous commented Dec 2, 2024

@zamazan4ik Thank you so much for taking the time to investigate LTO performance with Pathway production builds.

Assigning this enhancement for further review in the team.

@dxtrous
Copy link
Member

dxtrous commented Dec 4, 2024

Thank you for bearing with us here.
@KamilPiechowiak has investigated this question and confirmed your findings @zamazan4ik.
The LTO-built package is indeed lighter (50MB -> 43MB) and not-slower or marginally faster in benchmarks.

The issue is that the build time increases from ~2 minutes to ~30 minutes. We aim to build and tests package everywhere in the same way, and this would complicate the internal workflow (CI/CD setup. At a pure human productivity level, waiting an extra half-hour for tests to complete before merging a pull request might be problematic for our workflows.

I would propose to keep this one open, and see if we eventually figure something out.
Looping in @pw-ppodhajski as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants