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) #1010

Open
zamazan4ik opened this issue Nov 29, 2024 · 6 comments
Open

Enable Link-Time Optimization (LTO) #1010

zamazan4ik opened this issue Nov 29, 2024 · 6 comments
Labels
build Build related issues enhancement New feature or request

Comments

@zamazan4ik
Copy link
Contributor

zamazan4ik commented Nov 29, 2024

Hi!

I noticed that in the build scripts 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 (similar pages exist for C compilers like GCC and Clang - -flto compiler switch).

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 application. E.g., check cargo-outdated Release profile.

Basically, it can be enabled with the following lines for the Rust part:

[profile.release]
lto = true

I have made quick tests (Fedora 41, Rustc 1.83) by adding lto = true to the Release profile. The binary size reduction is the following:

  • scp_bpflang: from 5 Mib to 3.9 Mib
  • scx_flash: from 4.9 Mib to 3.9 Mib
  • scx_lavd: from 5.3 Mib to 4.2 Mib
  • scx_layered: from 6 Mib to 4.7 Mib
  • scx_loader: from 6 Mib to 4.5 Mib
  • scx_mitosis: from 2.1 Mib to 1.8 Mib
  • scx_rlfifo: from 3.5 Mib to 2.8 Mib
  • scx_rustland: from 5 to 3.9 Mib
  • scx_rusty: from 5.5 Mib to 4.4 Mib

I also suggest enabling LTO for the C part of the project - didn't perform such tests though but it should work too.

We discussed a bit this topic with @arighi in Discord - I will provide a PR for the Rust part of the project with enabling LTO. Regarding the C part - I am not sure since I am not an expert in Meson.

Thank you.

zamazan4ik added a commit to zamazan4ik/scx that referenced this issue Nov 29, 2024
Enable Link-Time Optimization (LTO) for Rust schedulers. It improves the
binary size and allows to a compiler perform more aggressive
optimizations.

More details in sched-ext#1010
@hodgesds
Copy link
Contributor

hodgesds commented Nov 29, 2024

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.

I pretty much only run release builds for development. I think this idea makes sense in general, but it should be done with a separate profile/config on Cargo/Meson to work.

I suggest adding an additional dist or release-lto profile where in addition to regular release optimizations LTO will also be added

This is a good idea.

@hodgesds hodgesds added enhancement New feature or request build Build related issues labels Nov 29, 2024
@likewhatevs
Copy link
Contributor

I pretty much only run release builds for development. I think this idea makes sense in general, but it should be done with a separate profile/config on Cargo/Meson to work.

yeah I just figured I'd stop doing this if this change were made, but a separate profile is a better idea tbh. this change as is would make ci a bit slower also.

@berkus
Copy link

berkus commented Nov 29, 2024

I think this idea makes sense in general, but it should be done with a separate profile/

It makes sense for release profile to be used for.. uhm.. releases. And a dev profile can be set up for development in the necessary way.

@likewhatevs
Copy link
Contributor

It makes sense for release profile to be used for.. uhm.. releases. And a dev profile can be set up for development in the necessary way.

Not super opposed to this (nor super in support of it, the rust code isn't doing anything too heavy tbh), but we're running into bad queue'ing on GH free tier already and are a bit unsure how to deal with this (🤔), and we would want to run a build with this profile per commit on ci.

Misc btw, if we're gonna add LTO, we may as well set CUs to 1 (so LTO works best), opt level to 3.

@JakeHillion
Copy link
Contributor

I think there is an argument for LTO by default given we care about performance, e.g. if a random person clones scx and does some performance testing having the best we can by default (release) makes sense. Whether it makes any real difference is the other question. I don't think binary size is a good argument for changing the defaults though, that can be done in release-lto. Thanks for the work so far!

zamazan4ik added a commit to zamazan4ik/scx that referenced this issue Jan 3, 2025
Enable Link-Time Optimization (LTO) for Rust schedulers. It improves the
binary size and allows to a compiler perform more aggressive
optimizations.

More details in sched-ext#1010
@JohnRTitor
Copy link
Contributor

Regarding the C part - I am not sure since I am not an expert in Meson.

I opened #1155, but got stuck at a linker error. (Not experienced enough with meson to debug this, meson is probably stripping the archive index, which ld linker needs).

Any help would be nice!

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

No branches or pull requests

6 participants