Effects of `lto="fat"` in upstream consumers

I've created a vanilla (i.e. the default crate-type=["lib"]) crate A that heavily benefits from LTO, so I specified

lto = "fat"

lto = "fat"

in its Cargo.toml. Indeed, when I run the crate's benchmarks, they're 25% faster.

What happens when another binary crate B takes a dependency on A:

  • No LTO for anyone in B unless B specifies LTO?
  • LTO for A and its transitive dependency closure, but not the rest of B?

My current model, which is based solely on intuition (and not any documentation) is that lto, link time optimization, is done once per binary/lib, not a per-crate option. Thus, it just takes the value from the "root" crate ?

From the Cargo book:

Cargo only looks at the profile settings in the Cargo.toml manifest at the root of the workspace. Profile settings defined in dependencies will be ignored.

1 Like