LTO optimisation

I am trying to use lto = true optimisation for my project which has several crates in it. However, the performance seems to have regressed while using this optimisation. Is there any general or specific reason for this? I am using compiler optimisation along with this as well.

Generally it should be faster, but LTO affects inlining heuristics, and it's possible that you've run into an edge case where more inlining causes worse performance.

There's also lto = "fat" and codegen-units that you can tweak.

Profile your code to see which parts are slower.

Check cargo-bloat to see if you have some unexpectedly large functions.

You can use #[inline] and #[inline(never)] to control inlining, and #[cold] to move less-used code out of hot paths.

There's also cargo-pgo that can improve effectiveness of LTO.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.