Enable Link-Time Optimization (LTO) and codegen-units = 1 for Release builds
- Dominant language
- Rust
- Stars
- 503
- Forks
- 61
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 91
Description
Hi!
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 more about LTO and its possible modes, I recommend starting from [this](https://doc.rust-lang.org/rustc/codegen-options/index.html#lto) Rustc documentation.
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](https://github.com/BurntSushi/ripgrep/blob/cbc598f245f3c157a872b69102653e2e349b6d92/Cargo.toml#L76).
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 42, Rust 1.89, the latest version of the project at the moment, `cargo build -r --workspace` command, without stripping) - here are the results:
| Profile \ Binary name | `sedona-cli` | `lib_lib.so` |
| --- | --- | --- |
| Release (current) | 151 Mib | 160 Mib |
| Release + ThinLTO + CU1 | 110 Mib | 115 Mib |
| Release + FatLTO + CU1 | 97 Mib | 100 Mib |
Clean build times:
* Release (current): 3m 12s
* Release + ThinLTO + CU1: 4m 28s
* Release + FatLTO + CU1: 9m 38s
I haven't done performance benchmark but expect that FatLTO version will be the most performant too.
Thank you.
Contributor guide
Research direction
Start with the root Cargo.toml and inspect the existing release profile, then review Rust's LTO documentation and the referenced ripgrep profile. Run cargo build -r --workspace and compare binary sizes and clean build times for the proposed settings. Done means the release configuration and its performance/build-time trade-offs are settled and validated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, performance
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100