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 agent's CPU performance a bit due to more aggressive compiler optimizations. If you want to read more about LTO and its possible modes, I recommend starting from this Rustc documentation. Additionally, codegen-units = 1 (CU1) option can help too in a similar to LTO way, so I recommend to enable it as well.
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 this ripgrep profile.
Basically, it can be enabled with the following lines to the root Cargo.toml file:
[profile.release]
codegen-units = 1
lto = true # FatLTO - the most aggressive LTO version
<possible other options like strip = true>
Adding this change directly to Cargo profile will allow you to apply automatically these optimizations everywhere "downstream" in the build pipeline like already existing Dockerfiles.
I have made quick tests (AMD Ryzen 9 5900x, Fedora 43, Rust 1.94, the latest version of the project at the moment, cargo build --release command, without stripping) - here are the results:
- Current Release profile: 34 Mib, clean build time: 1m 22s
- Release profile + ThinLTO + CU1: 27 Mib, clean build time: 1m 54s
- Release profile + FatLTO + CU1: 23 Mib, clean build time: 2m 48s
Build time increase shouldn't be a problem since we enable it only for the Release profile. From performance perspective, I expect that FatLTO + CU1 is also the most performant configuration (due to the most aggressive compiler optimizations) - however, I haven't made such benches (at least yet).
Thank you.
Hi!
I noticed that in the
Cargo.tomlfile 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 agent's CPU performance a bit due to more aggressive compiler optimizations. If you want to read more about LTO and its possible modes, I recommend starting from this Rustc documentation. Additionally,codegen-units = 1(CU1) option can help too in a similar to LTO way, so I recommend to enable it as well.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 this
ripgrepprofile.Basically, it can be enabled with the following lines to the root Cargo.toml file:
Adding this change directly to Cargo profile will allow you to apply automatically these optimizations everywhere "downstream" in the build pipeline like already existing Dockerfiles.
I have made quick tests (AMD Ryzen 9 5900x, Fedora 43, Rust 1.94, the latest version of the project at the moment,
cargo build --releasecommand, without stripping) - here are the results:Build time increase shouldn't be a problem since we enable it only for the Release profile. From performance perspective, I expect that FatLTO + CU1 is also the most performant configuration (due to the most aggressive compiler optimizations) - however, I haven't made such benches (at least yet).
Thank you.